NSItem: handle health/armor/ammo drops outside Touch.

New cmds: giveInventoryItem, removeInventoryItem, removeAllInventoryItems
This commit is contained in:
Marco Cawthorne 2024-07-26 12:53:57 -07:00
parent 760bc4a8fa
commit 935c0fd543
Signed by: eukara
GPG key ID: CE2032F0A2882A22
5 changed files with 70 additions and 107 deletions

View file

@ -236,13 +236,6 @@ CMD_ListModelFramegroups(void)
print("} framegroups_e;\n");
}
static void
CMD_ListInventory(void)
{
NSNavAI_ListInventory((NSNavAI)pSeat->m_ePlayer);
}
/*
=================
Cmd_Parse
@ -452,84 +445,47 @@ Cmd_Parse(string sCMD)
case "-menu_right":
pSeat->m_iInputReload = false;
break;
/* client aliases for server commands */
case "addBot":
localcmd(sprintf("sv addBot %s\n", argv(1)));
break;
case "killAllBots":
localcmd("sv killAllBots\n");
break;
case "resetAllBotsGoals":
localcmd("sv resetAllBotsGoals\n");
break;
case "killClass":
localcmd(sprintf("sv killClass %s\n", argv(1)));
break;
case "killMovables":
localcmd("sv killMovables\n");
break;
case "trigger":
localcmd(sprintf("sv trigger %s\n", argv(1)));
break;
case "input":
localcmd(sprintf("sv input %s %s %s\n", argv(1), argv(2), argv(3)));
break;
case "listBotProfiles":
localcmd("sv listBotProfiles\n");
break;
case "listTargets":
localcmd("sv listTargets\n");
break;
case "teleport":
localcmd(sprintf("sv teleport %s\n", argv(1)));
break;
case "teleportToClass":
localcmd(sprintf("sv teleportToClass %s\n", argv(1)));
break;
case "respawnEntities":
localcmd("sv respawnEntities\n");
break;
case "spawnDef":
localcmd(sprintf("sv spawn %s\n", argv(1)));
break;
case "nodeAdd":
localcmd(sprintf("sv way addsingle %s\n", argv(1)));
break;
case "nodeDel":
localcmd(sprintf("sv way delete %s\n", argv(1)));
break;
case "nodeFlags":
localcmd(sprintf("sv way link %s\n", argv(1)));
break;
case "nodeLink":
localcmd(sprintf("sv way connect1 %s\n", argv(1)));
break;
case "nodeRadius":
localcmd(sprintf("sv way radius %s\n", argv(1)));
break;
case "nodeOffset":
localcmd(sprintf("sv way move %s\n", argv(1)));
break;
case "nodeUnlink":
localcmd(sprintf("sv way unlink1 %s\n", argv(1)));
break;
case "traceMaterial":
localcmd("sv traceMaterial\n");
localcmd(sprintf("sv %s\n", sCMD));
break;
/* client aliases for client commands */
case "listInventory":
case "giveInventoryItem":
case "removeInventoryItem":
case "removeAllInventoryItems":
case "listAmmo":
localcmd(sprintf("cmd %s\n", sCMD));
break;
case "listClientEntityDef":
EntityDef_DebugList();
break;
case "listServerEntityDef":
localcmd("sv listEntityDef\n");
break;
case "listInventory":
CMD_ListInventory();
break;
case "listAmmo":
Ammo_DebugList();
break;
case "bobup":
break;
case "bobdn":
@ -635,6 +591,10 @@ Cmd_Init(void)
registercommand("weapnext");
registercommand("weapprev");
registercommand("giveInventoryItem");
registercommand("removeInventoryItem");
registercommand("removeAllInventoryItems");
/* voting */
registercommand("vote");
registercommand("callvote");

View file

@ -59,6 +59,24 @@ Cmd_ParseClientCommand(NSClient sender, string cmd, int commandArguments)
msg = sprintf("we have %s minutes remaining", timestring);
bprint(PRINT_CHAT, msg);
break;
case "listInventory":
NSNavAI_ListInventory((NSNavAI)self);
break;
case "giveInventoryItem":
NSNavAI player = (NSNavAI)self;
player.GiveItem(argv(1));
break;
case "removeInventoryItem":
NSNavAI player = (NSNavAI)self;
player.RemoveItem(argv(1));
break;
case "removeAllInventoryItems":
NSNavAI player = (NSNavAI)self;
player.RemoveAllItems(false);
break;
case "listAmmo":
Ammo_DebugList();
break;
default:
clientcommand(sender, cmd);
}

View file

@ -241,12 +241,6 @@ Cmd_ParseServerCommand(void)
case "traceMaterial":
CMD_TraceMaterial();
break;
case "listPlayerInventory":
NSNavAI_ListInventory((NSNavAI)self);
break;
case "listInventory":
NSNavAI_ListInventory((NSNavAI)self);
break;
default:
return (false);
}

View file

@ -203,7 +203,6 @@ void
NSItem::Touch(entity eToucher)
{
NSClientPlayer pl = (NSClientPlayer)eToucher;
bool removeItem = false;
if (eToucher.classname != "player") {
return;
@ -216,47 +215,8 @@ NSItem::Touch(entity eToucher)
}
/* don't remove if AddItem fails */
if (m_bInvCarry) {
string itemToAdd = (m_strInvWeapon) ? m_strInvWeapon : classname;
if (pl.GiveItem(itemToAdd) == true) {
removeItem = true;
}
}
/* proceed */
if (m_iGiveHealth > 0i) {
if (pl.GetHealth() < 100) {
//Damage_Apply(pl, this, -m_iGiveHealth, 0, DMG_GENERIC);
pl.health = bound(0, pl.health + m_iGiveHealth, pl.max_health);
removeItem = true;
}
}
if (m_iGiveArmor > 0i) {
if (pl.armor < 100) {
pl.armor += (float)m_iGiveArmor;
removeItem = true;
if (pl.armor > 100) {
pl.armor = 100;
}
}
}
for (int i = 0; i < MAX_AMMO_TYPES; i++) {
if (m_GiveAmmo[i] > 0i && pl.GiveAmmo(i, m_GiveAmmo[i]) == true) {
removeItem = true;
}
}
if (removeItem == false) {
return;
}
Logging_Pickup(pl, this, __NULL__);
StartSoundDef(m_sndAcquire, CHAN_ITEM, true);
string itemToAdd = (m_strInvWeapon) ? m_strInvWeapon : classname;
pl.GiveItem(itemToAdd);
UseTargets(pl, TRIG_TOGGLE, m_flDelay);
if (real_owner || m_iWasDropped == 1 || cvar("sv_playerslots") == 1) {
@ -265,8 +225,6 @@ NSItem::Touch(entity eToucher)
Disappear();
ScheduleThink(PickupRespawn, 30.0f);
}
OnPickup();
}
void
@ -550,7 +508,7 @@ void
NSItem::RemovedFromInventory(void)
{
#ifdef SERVER
BecomePickup();
//BecomePickup();
#endif
}
@ -565,6 +523,32 @@ void
NSItem::_AddedCallback(void)
{
#ifdef SERVER
NSNavAI pl = (NSNavAI)owner;
if (m_iGiveHealth > 0i) {
if (pl.GetHealth() < 100) {
//Damage_Apply(pl, this, -m_iGiveHealth, 0, DMG_GENERIC);
pl.health = bound(0, pl.health + m_iGiveHealth, pl.max_health);
}
}
if (m_iGiveArmor > 0i) {
if (pl.armor < 100) {
pl.armor += (float)m_iGiveArmor;
if (pl.armor > 100) {
pl.armor = 100;
}
}
}
for (int i = 0; i < MAX_AMMO_TYPES; i++) {
pl.GiveAmmo(i, m_GiveAmmo[i]);
}
Logging_Pickup(pl, this, __NULL__);
StartSoundDef(m_sndAcquire, CHAN_ITEM, true);
OnPickup();
Disappear();
#endif

View file

@ -689,6 +689,8 @@ NSNavAI::GiveItem(string itemName)
NSItem linkedList = __NULL__;
NSItem lastItem = __NULL__;
bool canCarry stof(EntityDef_GetKeyValue(itemName, "inv_carry")) ? true : false;
/* we do not have an item yet. */
if (!m_itemList) {
m_itemList = (NSItem)EntityDef_CreateClassname(itemName);
@ -747,6 +749,11 @@ NSNavAI::GiveItem(string itemName)
SwitchToExactWeapon((NSWeapon)linkedList);
}
/* items (not weapons) may not be added permanently by default */
if (canCarry == false && linkedList.IsWeapon() == false) {
RemoveItem(itemName);
}
return (true);
#else
return (false);