mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-04-28 23:35:23 +00:00
replenishing supply of thrown grenades from player inventory; pulled in locker search for Player.Find to avoid wrongful indexing
This commit is contained in:
parent
ddf2f53d8a
commit
ba49b5859e
2 changed files with 55 additions and 5 deletions
|
|
@ -200,10 +200,7 @@ class Player(private val core : Avatar) extends PlanetSideGameObject with Factio
|
||||||
case Some(index) =>
|
case Some(index) =>
|
||||||
Some(index)
|
Some(index)
|
||||||
case None =>
|
case None =>
|
||||||
if(Locker.Find(guid).isDefined) {
|
if(freeHand.Equipment.isDefined && freeHand.Equipment.get.GUID == guid) {
|
||||||
Some(5)
|
|
||||||
}
|
|
||||||
else if(freeHand.Equipment.isDefined && freeHand.Equipment.get.GUID == guid) {
|
|
||||||
Some(Player.FreeHandSlot)
|
Some(Player.FreeHandSlot)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -3263,6 +3263,29 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
||||||
previousAmount < desiredAmount
|
previousAmount < desiredAmount
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
def FindRestock(obj : Container, filterTest : (Equipment)=>Boolean, desiredAmount : Int) : List[InventoryItem] = {
|
||||||
|
var currentAmount : Int = 0
|
||||||
|
obj.Inventory.Items
|
||||||
|
.map({ case ((_, item)) => item })
|
||||||
|
.filter(obj => filterTest(obj.obj))
|
||||||
|
.toList
|
||||||
|
.sortBy(_.start)
|
||||||
|
.takeWhile(entry => {
|
||||||
|
val previousAmount = currentAmount
|
||||||
|
currentAmount += (entry.obj match {
|
||||||
|
case obj : AmmoBox =>
|
||||||
|
obj.Capacity
|
||||||
|
case obj : Tool =>
|
||||||
|
if(GlobalDefinitions.isGrenade(obj.Definition)) {
|
||||||
|
obj.Magazine
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
previousAmount < desiredAmount
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an object that contains a box of amunition in its `Inventory` at a certain location,
|
* Given an object that contains a box of amunition in its `Inventory` at a certain location,
|
||||||
|
|
@ -3404,13 +3427,43 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
||||||
//TODO this is temporary and will be replaced by more appropriate functionality in the future.
|
//TODO this is temporary and will be replaced by more appropriate functionality in the future.
|
||||||
val tdef = tool.Definition
|
val tdef = tool.Definition
|
||||||
if(GlobalDefinitions.isGrenade(tdef)) {
|
if(GlobalDefinitions.isGrenade(tdef)) {
|
||||||
taskResolver ! RemoveEquipmentFromSlot(player, tool, player.Find(tool).get)
|
val findGrenades : (Equipment)=>Boolean = FindGrenadesLike(tool.AmmoType)
|
||||||
|
FindRestock(player, findGrenades, 3) match {
|
||||||
|
case Nil =>
|
||||||
|
taskResolver ! RemoveEquipmentFromSlot(player, tool, player.Find(tool).get)
|
||||||
|
|
||||||
|
case x :: xs => //this is similar to ReloadMessage
|
||||||
|
val box = x.obj.asInstanceOf[Tool]
|
||||||
|
val tailReloadValue : Int = if(xs.isEmpty) { 0 } else { xs.map(_.obj.asInstanceOf[Tool].Magazine).reduce(_ + _) }
|
||||||
|
val sumReloadValue : Int = box.Magazine + tailReloadValue
|
||||||
|
val actualReloadValue = (if(sumReloadValue <= 3) {
|
||||||
|
taskResolver ! RemoveEquipmentFromSlot(player, x.obj, x.start)
|
||||||
|
sumReloadValue
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ModifyAmmunition(player)(box.AmmoSlot.Box, 3 - tailReloadValue)
|
||||||
|
3
|
||||||
|
})
|
||||||
|
ModifyAmmunition(player)(tool.AmmoSlot.Box, -actualReloadValue) //grenades already in holster (negative because empty)
|
||||||
|
xs.foreach(item => {
|
||||||
|
taskResolver ! RemoveEquipmentFromSlot(player, item.obj, item.start)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(tdef == GlobalDefinitions.phoenix) {
|
else if(tdef == GlobalDefinitions.phoenix) {
|
||||||
taskResolver ! RemoveEquipmentFromSlot(player, tool, player.Find(tool).get)
|
taskResolver ! RemoveEquipmentFromSlot(player, tool, player.Find(tool).get)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def FindGrenadesLike(grenadeType : Ammo.Value)(e : Equipment) : Boolean = {
|
||||||
|
e match {
|
||||||
|
case t : Tool =>
|
||||||
|
t.AmmoType == grenadeType
|
||||||
|
case _ =>
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A predicate used to determine if an `InventoryItem` object contains `Equipment` that should be dropped.
|
* A predicate used to determine if an `InventoryItem` object contains `Equipment` that should be dropped.
|
||||||
* Used to filter through lists of object data before it is placed into a player's inventory.
|
* Used to filter through lists of object data before it is placed into a player's inventory.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue