/** * Cmd_Drop_f * * Drop an inventory item. */ public static void Drop_f(edict_t ent) { int index; gitem_t it; string s; s = Cmd.Args(); it = GameItems.FindItem(s); if (it == null) { SV_GAME.PF_cprintfhigh(ent, "unknown item: " + s + "\n"); return; } if (it.drop == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n"); return; } index = GameItems.ITEM_INDEX(it); if (0 == ent.client.pers.inventory[index]) { SV_GAME.PF_cprintfhigh(ent, "Out of item: " + s + "\n"); return; } it.drop.drop(ent, it); }
/** * Cmd_Use_f * * Use an inventory item. */ public static void Use_f(edict_t ent) { int index; gitem_t it; string s; s = Cmd.Args(); it = GameItems.FindItem(s); Com.dprintln("using:" + s); if (it == null) { SV_GAME.PF_cprintfhigh(ent, "unknown item: " + s + "\n"); return; } if (it.use == null) { SV_GAME.PF_cprintfhigh(ent, "Item is not usable.\n"); return; } index = GameItems.ITEM_INDEX(it); if (0 == ent.client.pers.inventory[index]) { SV_GAME.PF_cprintfhigh(ent, "Out of item: " + s + "\n"); return; } it.use.use(ent, it); }
//======================================================================= /* * =============== * G_SetStats * =============== */ public static void G_SetStats(edict_t ent) { gitem_t item; int index, cells = 0; int power_armor_type; // // health // ent.client.ps.stats[Defines.STAT_HEALTH_ICON] = (short)GameBase.level.pic_health; ent.client.ps.stats[Defines.STAT_HEALTH] = (short)ent.health; // // ammo // if (0 == ent.client.ammo_index /* * || * !ent.client.pers.inventory[ent.client.ammo_index] */ ) { ent.client.ps.stats[Defines.STAT_AMMO_ICON] = 0; ent.client.ps.stats[Defines.STAT_AMMO] = 0; } else { item = GameItemList.itemlist[ent.client.ammo_index]; ent.client.ps.stats[Defines.STAT_AMMO_ICON] = (short)GameBase.gi.imageindex(item.icon); ent.client.ps.stats[Defines.STAT_AMMO] = (short)ent.client.pers.inventory[ent.client.ammo_index]; } // // armor // power_armor_type = GameItems.PowerArmorType(ent); if (power_armor_type != 0) { cells = ent.client.pers.inventory[GameItems.ITEM_INDEX(GameItems.FindItem("cells"))]; if (cells == 0) { // ran out of cells for power armor ent.flags &= ~Defines.FL_POWER_ARMOR; GameBase.gi.sound(ent, Defines.CHAN_ITEM, GameBase.gi.soundindex("misc/power2.wav"), 1, Defines.ATTN_NORM, 0); power_armor_type = 0; ; } } index = GameItems.ArmorIndex(ent); if (power_armor_type != 0 && (0 == index || 0 != (GameBase.level.framenum & 8))) { // flash // between // power // armor // and // other // armor // icon ent.client.ps.stats[Defines.STAT_ARMOR_ICON] = (short)GameBase.gi.imageindex("i_powershield"); ent.client.ps.stats[Defines.STAT_ARMOR] = (short)cells; } else if (index != 0) { item = GameItems.GetItemByIndex(index); ent.client.ps.stats[Defines.STAT_ARMOR_ICON] = (short)GameBase.gi.imageindex(item.icon); ent.client.ps.stats[Defines.STAT_ARMOR] = (short)ent.client.pers.inventory[index]; } else { ent.client.ps.stats[Defines.STAT_ARMOR_ICON] = 0; ent.client.ps.stats[Defines.STAT_ARMOR] = 0; } // // pickup message // if (GameBase.level.time > ent.client.pickup_msg_time) { ent.client.ps.stats[Defines.STAT_PICKUP_ICON] = 0; ent.client.ps.stats[Defines.STAT_PICKUP_STRING] = 0; } // // timers // if (ent.client.quad_framenum > GameBase.level.framenum) { ent.client.ps.stats[Defines.STAT_TIMER_ICON] = (short)GameBase.gi.imageindex("p_quad"); ent.client.ps.stats[Defines.STAT_TIMER] = (short)((ent.client.quad_framenum - GameBase.level.framenum) / 10); } else if (ent.client.invincible_framenum > GameBase.level.framenum) { ent.client.ps.stats[Defines.STAT_TIMER_ICON] = (short)GameBase.gi.imageindex("p_invulnerability"); ent.client.ps.stats[Defines.STAT_TIMER] = (short)((ent.client.invincible_framenum - GameBase.level.framenum) / 10); } else if (ent.client.enviro_framenum > GameBase.level.framenum) { ent.client.ps.stats[Defines.STAT_TIMER_ICON] = (short)GameBase.gi.imageindex("p_envirosuit"); ent.client.ps.stats[Defines.STAT_TIMER] = (short)((ent.client.enviro_framenum - GameBase.level.framenum) / 10); } else if (ent.client.breather_framenum > GameBase.level.framenum) { ent.client.ps.stats[Defines.STAT_TIMER_ICON] = (short)GameBase.gi.imageindex("p_rebreather"); ent.client.ps.stats[Defines.STAT_TIMER] = (short)((ent.client.breather_framenum - GameBase.level.framenum) / 10); } else { ent.client.ps.stats[Defines.STAT_TIMER_ICON] = 0; ent.client.ps.stats[Defines.STAT_TIMER] = 0; } // // selected item // // bugfix rst if (ent.client.pers.selected_item <= 0) { ent.client.ps.stats[Defines.STAT_SELECTED_ICON] = 0; } else { ent.client.ps.stats[Defines.STAT_SELECTED_ICON] = (short)GameBase.gi.imageindex(GameItemList.itemlist[ent.client.pers.selected_item].icon); } ent.client.ps.stats[Defines.STAT_SELECTED_ITEM] = (short)ent.client.pers.selected_item; // // layouts // ent.client.ps.stats[Defines.STAT_LAYOUTS] = 0; if (GameBase.deathmatch.value != 0) { if (ent.client.pers.health <= 0 || GameBase.level.intermissiontime != 0 || ent.client.showscores) { ent.client.ps.stats[Defines.STAT_LAYOUTS] |= 1; } if (ent.client.showinventory && ent.client.pers.health > 0) { ent.client.ps.stats[Defines.STAT_LAYOUTS] |= 2; } } else { if (ent.client.showscores || ent.client.showhelp) { ent.client.ps.stats[Defines.STAT_LAYOUTS] |= 1; } if (ent.client.showinventory && ent.client.pers.health > 0) { ent.client.ps.stats[Defines.STAT_LAYOUTS] |= 2; } } // // frags // ent.client.ps.stats[Defines.STAT_FRAGS] = (short)ent.client.resp.score; // // help icon / current weapon if not shown // if (ent.client.pers.helpchanged != 0 && (GameBase.level.framenum & 8) != 0) { ent.client.ps.stats[Defines.STAT_HELPICON] = (short)GameBase.gi.imageindex("i_help"); } else if ((ent.client.pers.hand == Defines.CENTER_HANDED || ent.client.ps.fov > 91) && ent.client.pers.weapon != null) { ent.client.ps.stats[Defines.STAT_HELPICON] = (short)GameBase.gi.imageindex(ent.client.pers.weapon.icon); } else { ent.client.ps.stats[Defines.STAT_HELPICON] = 0; } ent.client.ps.stats[Defines.STAT_SPECTATOR] = 0; }
/** * Cmd_Give_f * * Give items to a client. */ public static void Give_f(edict_t ent) { string name; gitem_t it; int index; int i; bool give_all; edict_t it_ent; if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0) { SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\n"); return; } name = Cmd.Args(); if (0 == Lib.Q_stricmp(name, "all")) { give_all = true; } else { give_all = false; } if (give_all || 0 == Lib.Q_stricmp(Cmd.Argv(1), "health")) { if (Cmd.Argc() == 3) { ent.health = Lib.atoi(Cmd.Argv(2)); } else { ent.health = ent.max_health; } if (!give_all) { return; } } if (give_all || 0 == Lib.Q_stricmp(name, "weapons")) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (null == it.pickup) { continue; } if (0 == (it.flags & Defines.IT_WEAPON)) { continue; } ent.client.pers.inventory[i] += 1; } if (!give_all) { return; } } if (give_all || 0 == Lib.Q_stricmp(name, "ammo")) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (null == it.pickup) { continue; } if (0 == (it.flags & Defines.IT_AMMO)) { continue; } GameItems.Add_Ammo(ent, it, 1000); } if (!give_all) { return; } } if (give_all || Lib.Q_stricmp(name, "armor") == 0) { gitem_armor_t info; it = GameItems.FindItem("Jacket Armor"); ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0; it = GameItems.FindItem("Combat Armor"); ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0; it = GameItems.FindItem("Body Armor"); info = (gitem_armor_t)it.info; ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = info.max_count; if (!give_all) { return; } } if (give_all || Lib.Q_stricmp(name, "Power Shield") == 0) { it = GameItems.FindItem("Power Shield"); it_ent = GameUtil.G_Spawn(); it_ent.classname = it.classname; GameItems.SpawnItem(it_ent, it); GameItems.Touch_Item.touch(it_ent, ent, GameBase.dummyplane, null); if (it_ent.inuse) { GameUtil.G_FreeEdict(it_ent); } if (!give_all) { return; } } if (give_all) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (it.pickup != null) { continue; } if ((it.flags & (Defines.IT_ARMOR | Defines.IT_WEAPON | Defines.IT_AMMO)) != 0) { continue; } ent.client.pers.inventory[i] = 1; } return; } it = GameItems.FindItem(name); if (it == null) { name = Cmd.Argv(1); it = GameItems.FindItem(name); if (it == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item\n"); return; } } if (it.pickup == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "non-pickup item\n"); return; } index = GameItems.ITEM_INDEX(it); if ((it.flags & Defines.IT_AMMO) != 0) { if (Cmd.Argc() == 3) { ent.client.pers.inventory[index] = Lib.atoi(Cmd.Argv(2)); } else { ent.client.pers.inventory[index] += it.quantity; } } else { it_ent = GameUtil.G_Spawn(); it_ent.classname = it.classname; GameItems.SpawnItem(it_ent, it); GameItems.Touch_Item.touch(it_ent, ent, GameBase.dummyplane, null); if (it_ent.inuse) { GameUtil.G_FreeEdict(it_ent); } } }
private static int CheckPowerArmor(edict_t ent, float[] point, float[] normal, int damage, int dflags) { gclient_t client; int save; int power_armor_type; var index = 0; int damagePerCell; int pa_te_type; var power = 0; int power_used; if (damage == 0) { return(0); } client = ent.client; if ((dflags & Defines.DAMAGE_NO_ARMOR) != 0) { return(0); } if (client != null) { power_armor_type = GameItems.PowerArmorType(ent); if (power_armor_type != Defines.POWER_ARMOR_NONE) { index = GameItems.ITEM_INDEX(GameItems.FindItem("Cells")); power = client.pers.inventory[index]; } } else if ((ent.svflags & Defines.SVF_MONSTER) != 0) { power_armor_type = ent.monsterinfo.power_armor_type; power = ent.monsterinfo.power_armor_power; } else { return(0); } if (power_armor_type == Defines.POWER_ARMOR_NONE) { return(0); } if (power == 0) { return(0); } if (power_armor_type == Defines.POWER_ARMOR_SCREEN) { float[] vec = { 0, 0, 0 }; float dot; float[] forward = { 0, 0, 0 }; // only works if damage point is in front Math3D.AngleVectors(ent.s.angles, forward, null, null); Math3D.VectorSubtract(point, ent.s.origin, vec); Math3D.VectorNormalize(vec); dot = Math3D.DotProduct(vec, forward); if (dot <= 0.3) { return(0); } damagePerCell = 1; pa_te_type = Defines.TE_SCREEN_SPARKS; damage = damage / 3; } else { damagePerCell = 2; pa_te_type = Defines.TE_SHIELD_SPARKS; damage = 2 * damage / 3; } save = power * damagePerCell; if (save == 0) { return(0); } if (save > damage) { save = damage; } GameCombat.SpawnDamage(pa_te_type, point, normal, save); ent.powerarmor_time = GameBase.level.time + 0.2f; power_used = save / damagePerCell; if (client != null) { client.pers.inventory[index] -= power_used; } else { ent.monsterinfo.power_armor_power -= power_used; } return(save); }