Fix bug getting inventory items
This commit is contained in:
parent
e51223df88
commit
94dfce126c
@ -154,22 +154,17 @@ let handleHack (ctx : IDiscordContext) =
|
|||||||
let handleArsenal (ctx : IDiscordContext) =
|
let handleArsenal (ctx : IDiscordContext) =
|
||||||
Game.executePlayerAction ctx (fun player -> async {
|
Game.executePlayerAction ctx (fun player -> async {
|
||||||
let hasStockWeapons = Player.getHacks player |> Array.exists (fun item -> item.Id = defaultHack.Id)
|
let hasStockWeapons = Player.getHacks player |> Array.exists (fun item -> item.Id = defaultHack.Id)
|
||||||
let updatedPlayer = Player.removeExpiredActions false player
|
let updatedPlayer =
|
||||||
let newPlayer =
|
|
||||||
if not hasStockWeapons then {
|
if not hasStockWeapons then {
|
||||||
updatedPlayer with
|
Player.removeExpiredActions false player with
|
||||||
Events = if not (player.Events |> Array.exists (fun act -> act.Adversary = Sensei))
|
Events = TrainerEvents |> Array.append player.Events
|
||||||
then TrainerEvents
|
Inventory = [| defaultHack ; defaultShield |] |> Array.append player.Inventory
|
||||||
else [||]
|
|
||||||
|> Array.append player.Events
|
|
||||||
Inventory = if not hasStockWeapons then [| defaultHack ; defaultShield |] else Array.empty
|
|
||||||
|> Array.append player.Inventory
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
updatedPlayer
|
Player.removeExpiredActions false player
|
||||||
if not hasStockWeapons then
|
if not hasStockWeapons then
|
||||||
do! DbService.updatePlayer newPlayer
|
do! DbService.updatePlayer updatedPlayer
|
||||||
let embed = Embeds.getArsenalEmbed newPlayer
|
let embed = Embeds.getArsenalEmbed updatedPlayer
|
||||||
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
||||||
if not (player.Achievements |> Array.contains trainerAchievement) then
|
if not (player.Achievements |> Array.contains trainerAchievement) then
|
||||||
do! Async.Sleep 3000
|
do! Async.Sleep 3000
|
||||||
|
@ -23,8 +23,7 @@ let mapBack (bson : BsonDocument) : PlayerData =
|
|||||||
Inventory =
|
Inventory =
|
||||||
tryWithDefault bson "Inventory" [||] (fun v ->
|
tryWithDefault bson "Inventory" [||] (fun v ->
|
||||||
v.AsBsonArray
|
v.AsBsonArray
|
||||||
|> Seq.map (fun (bv : BsonValue) -> bv.AsInt32)
|
|> Seq.map (fun (bv : BsonValue) -> BsonSerializer.Deserialize<Item>(bv.ToBsonDocument()))
|
||||||
|> Seq.map (fun w -> Armory.battleItems |> Array.find (fun w' -> w = w'.Id))
|
|
||||||
|> Seq.toArray)
|
|> Seq.toArray)
|
||||||
Events = tryWithDefault bson "Events" [||] (fun v ->
|
Events = tryWithDefault bson "Events" [||] (fun v ->
|
||||||
v.AsBsonArray
|
v.AsBsonArray
|
||||||
@ -47,11 +46,10 @@ let tryFindPlayer (id : uint64) =
|
|||||||
let! player = players.FindAsync<BsonDocument>(filter) |> Async.AwaitTask
|
let! player = players.FindAsync<BsonDocument>(filter) |> Async.AwaitTask
|
||||||
match player.FirstOrDefault() with
|
match player.FirstOrDefault() with
|
||||||
| null -> return None
|
| null -> return None
|
||||||
| p -> return p
|
| p ->
|
||||||
.GetValue("Player")
|
let v = p.GetValue("Player")
|
||||||
.ToBsonDocument()
|
let playerData = v.ToBsonDocument() |> mapBack
|
||||||
|> mapBack
|
return Some playerData
|
||||||
|> Some
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let insertNewPlayer (player : PlayerData) =
|
let insertNewPlayer (player : PlayerData) =
|
||||||
|
@ -69,6 +69,14 @@ module Types =
|
|||||||
Cooldown : int<mins>
|
Cooldown : int<mins>
|
||||||
Attributes : ItemAttributes
|
Attributes : ItemAttributes
|
||||||
}
|
}
|
||||||
|
with static member empty =
|
||||||
|
{ Id = -1
|
||||||
|
Name = "None"
|
||||||
|
Price = 0<GBT>
|
||||||
|
Type = ItemType.Hack
|
||||||
|
Power = 0
|
||||||
|
Cooldown = 0<mins>
|
||||||
|
Attributes = ItemAttributes.empty }
|
||||||
|
|
||||||
type HackResult =
|
type HackResult =
|
||||||
| Strong
|
| Strong
|
||||||
|
Loading…
x
Reference in New Issue
Block a user