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) =
|
||||
Game.executePlayerAction ctx (fun player -> async {
|
||||
let hasStockWeapons = Player.getHacks player |> Array.exists (fun item -> item.Id = defaultHack.Id)
|
||||
let updatedPlayer = Player.removeExpiredActions false player
|
||||
let newPlayer =
|
||||
let updatedPlayer =
|
||||
if not hasStockWeapons then {
|
||||
updatedPlayer with
|
||||
Events = if not (player.Events |> Array.exists (fun act -> act.Adversary = Sensei))
|
||||
then TrainerEvents
|
||||
else [||]
|
||||
|> Array.append player.Events
|
||||
Inventory = if not hasStockWeapons then [| defaultHack ; defaultShield |] else Array.empty
|
||||
|> Array.append player.Inventory
|
||||
Player.removeExpiredActions false player with
|
||||
Events = TrainerEvents |> Array.append player.Events
|
||||
Inventory = [| defaultHack ; defaultShield |] |> Array.append player.Inventory
|
||||
}
|
||||
else
|
||||
updatedPlayer
|
||||
Player.removeExpiredActions false player
|
||||
if not hasStockWeapons then
|
||||
do! DbService.updatePlayer newPlayer
|
||||
let embed = Embeds.getArsenalEmbed newPlayer
|
||||
do! DbService.updatePlayer updatedPlayer
|
||||
let embed = Embeds.getArsenalEmbed updatedPlayer
|
||||
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
||||
if not (player.Achievements |> Array.contains trainerAchievement) then
|
||||
do! Async.Sleep 3000
|
||||
|
@ -23,8 +23,7 @@ let mapBack (bson : BsonDocument) : PlayerData =
|
||||
Inventory =
|
||||
tryWithDefault bson "Inventory" [||] (fun v ->
|
||||
v.AsBsonArray
|
||||
|> Seq.map (fun (bv : BsonValue) -> bv.AsInt32)
|
||||
|> Seq.map (fun w -> Armory.battleItems |> Array.find (fun w' -> w = w'.Id))
|
||||
|> Seq.map (fun (bv : BsonValue) -> BsonSerializer.Deserialize<Item>(bv.ToBsonDocument()))
|
||||
|> Seq.toArray)
|
||||
Events = tryWithDefault bson "Events" [||] (fun v ->
|
||||
v.AsBsonArray
|
||||
@ -47,11 +46,10 @@ let tryFindPlayer (id : uint64) =
|
||||
let! player = players.FindAsync<BsonDocument>(filter) |> Async.AwaitTask
|
||||
match player.FirstOrDefault() with
|
||||
| null -> return None
|
||||
| p -> return p
|
||||
.GetValue("Player")
|
||||
.ToBsonDocument()
|
||||
|> mapBack
|
||||
|> Some
|
||||
| p ->
|
||||
let v = p.GetValue("Player")
|
||||
let playerData = v.ToBsonDocument() |> mapBack
|
||||
return Some playerData
|
||||
}
|
||||
|
||||
let insertNewPlayer (player : PlayerData) =
|
||||
|
@ -69,6 +69,14 @@ module Types =
|
||||
Cooldown : int<mins>
|
||||
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 =
|
||||
| Strong
|
||||
|
Loading…
x
Reference in New Issue
Block a user