📄 gameitems.java
字号:
/*Copyright (C) 1997-2001 Id Software, Inc.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/// Created on 16.11.2005 by RST.// $Id: GameItems.java,v 1.4 2006/01/21 21:53:32 salomo Exp $package jake2.game;import jake2.Defines;import jake2.qcommon.Com;import jake2.util.Lib;import jake2.util.Math3D;import java.util.StringTokenizer;public class GameItems { public static gitem_armor_t jacketarmor_info = new gitem_armor_t(25, 50, .30f, .00f, Defines.ARMOR_JACKET); public static gitem_armor_t combatarmor_info = new gitem_armor_t(50, 100, .60f, .30f, Defines.ARMOR_COMBAT); public static gitem_armor_t bodyarmor_info = new gitem_armor_t(100, 200, .80f, .60f, Defines.ARMOR_BODY); static int quad_drop_timeout_hack = 0; static int jacket_armor_index; static int combat_armor_index; static int body_armor_index; static int power_screen_index; static int power_shield_index; static EntThinkAdapter DoRespawn = new EntThinkAdapter() { public String getID() { return "do_respawn";} public boolean think(edict_t ent) { if (ent.team != null) { edict_t master; int count; int choice = 0; master = ent.teammaster; // count the depth for (count = 0, ent = master; ent != null; ent = ent.chain, count++) ; choice = Lib.rand() % count; for (count = 0, ent = master; count < choice; ent = ent.chain, count++) ; } ent.svflags &= ~Defines.SVF_NOCLIENT; ent.solid = Defines.SOLID_TRIGGER; GameBase.gi.linkentity(ent); // send an effect ent.s.event = Defines.EV_ITEM_RESPAWN; return false; } }; static EntInteractAdapter Pickup_Pack = new EntInteractAdapter() { public String getID() { return "pickup_pack";} public boolean interact(edict_t ent, edict_t other) { gitem_t item; int index; if (other.client.pers.max_bullets < 300) other.client.pers.max_bullets = 300; if (other.client.pers.max_shells < 200) other.client.pers.max_shells = 200; if (other.client.pers.max_rockets < 100) other.client.pers.max_rockets = 100; if (other.client.pers.max_grenades < 100) other.client.pers.max_grenades = 100; if (other.client.pers.max_cells < 300) other.client.pers.max_cells = 300; if (other.client.pers.max_slugs < 100) other.client.pers.max_slugs = 100; item = FindItem("Bullets"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_bullets) other.client.pers.inventory[index] = other.client.pers.max_bullets; } item = FindItem("Shells"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_shells) other.client.pers.inventory[index] = other.client.pers.max_shells; } item = FindItem("Cells"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_cells) other.client.pers.inventory[index] = other.client.pers.max_cells; } item = FindItem("Grenades"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_grenades) other.client.pers.inventory[index] = other.client.pers.max_grenades; } item = FindItem("Rockets"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_rockets) other.client.pers.inventory[index] = other.client.pers.max_rockets; } item = FindItem("Slugs"); if (item != null) { index = ITEM_INDEX(item); other.client.pers.inventory[index] += item.quantity; if (other.client.pers.inventory[index] > other.client.pers.max_slugs) other.client.pers.inventory[index] = other.client.pers.max_slugs; } if (0 == (ent.spawnflags & Defines.DROPPED_ITEM) && (GameBase.deathmatch.value != 0)) SetRespawn(ent, ent.item.quantity); return true; } }; final static EntInteractAdapter Pickup_Health = new EntInteractAdapter() { public String getID() { return "pickup_health";} public boolean interact(edict_t ent, edict_t other) { if (0 == (ent.style & Defines.HEALTH_IGNORE_MAX)) if (other.health >= other.max_health) return false; other.health += ent.count; if (0 == (ent.style & Defines.HEALTH_IGNORE_MAX)) { if (other.health > other.max_health) other.health = other.max_health; } if (0 != (ent.style & Defines.HEALTH_TIMED)) { ent.think = GameUtil.MegaHealth_think; ent.nextthink = GameBase.level.time + 5f; ent.owner = other; ent.flags |= Defines.FL_RESPAWN; ent.svflags |= Defines.SVF_NOCLIENT; ent.solid = Defines.SOLID_NOT; } else { if (!((ent.spawnflags & Defines.DROPPED_ITEM) != 0) && (GameBase.deathmatch.value != 0)) SetRespawn(ent, 30); } return true; } }; static EntTouchAdapter Touch_Item = new EntTouchAdapter() { public String getID() { return "touch_item";} public void touch(edict_t ent, edict_t other, cplane_t plane, csurface_t surf) { boolean taken; if (ent.classname.equals("item_breather")) taken = false; if (other.client == null) return; if (other.health < 1) return; // dead people can't pickup if (ent.item.pickup == null) return; // not a grabbable item? taken = ent.item.pickup.interact(ent, other); if (taken) { // flash the screen other.client.bonus_alpha = 0.25f; // show icon and name on status bar other.client.ps.stats[Defines.STAT_PICKUP_ICON] = (short) GameBase.gi .imageindex(ent.item.icon); other.client.ps.stats[Defines.STAT_PICKUP_STRING] = (short) (Defines.CS_ITEMS + ITEM_INDEX(ent.item)); other.client.pickup_msg_time = GameBase.level.time + 3.0f; // change selected item if (ent.item.use != null) other.client.pers.selected_item = other.client.ps.stats[Defines.STAT_SELECTED_ITEM] = (short) ITEM_INDEX(ent.item); if (ent.item.pickup == Pickup_Health) { if (ent.count == 2) GameBase.gi.sound(other, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/s_health.wav"), 1, Defines.ATTN_NORM, 0); else if (ent.count == 10) GameBase.gi.sound(other, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/n_health.wav"), 1, Defines.ATTN_NORM, 0); else if (ent.count == 25) GameBase.gi.sound(other, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/l_health.wav"), 1, Defines.ATTN_NORM, 0); else // (ent.count == 100) GameBase.gi.sound(other, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/m_health.wav"), 1, Defines.ATTN_NORM, 0); } else if (ent.item.pickup_sound != null) { GameBase.gi.sound(other, Defines.CHAN_ITEM, GameBase.gi .soundindex(ent.item.pickup_sound), 1, Defines.ATTN_NORM, 0); } } if (0 == (ent.spawnflags & Defines.ITEM_TARGETS_USED)) { GameUtil.G_UseTargets(ent, other); ent.spawnflags |= Defines.ITEM_TARGETS_USED; } if (!taken) return; Com.dprintln("Picked up:" + ent.classname); if (!((GameBase.coop.value != 0) && (ent.item.flags & Defines.IT_STAY_COOP) != 0) || 0 != (ent.spawnflags & (Defines.DROPPED_ITEM | Defines.DROPPED_PLAYER_ITEM))) { if ((ent.flags & Defines.FL_RESPAWN) != 0) ent.flags &= ~Defines.FL_RESPAWN; else GameUtil.G_FreeEdict(ent); } } }; static EntTouchAdapter drop_temp_touch = new EntTouchAdapter() { public String getID() { return "drop_temp_touch";} public void touch(edict_t ent, edict_t other, cplane_t plane, csurface_t surf) { if (other == ent.owner) return; Touch_Item.touch(ent, other, plane, surf); } }; static EntThinkAdapter drop_make_touchable = new EntThinkAdapter() { public String getID() { return "drop_make_touchable";} public boolean think(edict_t ent) { ent.touch = Touch_Item; if (GameBase.deathmatch.value != 0) { ent.nextthink = GameBase.level.time + 29; ent.think = GameUtil.G_FreeEdictA; } return false; } }; static ItemUseAdapter Use_Quad = new ItemUseAdapter() { public String getID() { return "use_quad";} public void use(edict_t ent, gitem_t item) { int timeout; ent.client.pers.inventory[ITEM_INDEX(item)]--; GameUtil.ValidateSelectedItem(ent); if (quad_drop_timeout_hack != 0) { timeout = quad_drop_timeout_hack; quad_drop_timeout_hack = 0; } else { timeout = 300; } if (ent.client.quad_framenum > GameBase.level.framenum) ent.client.quad_framenum += timeout; else ent.client.quad_framenum = GameBase.level.framenum + timeout; GameBase.gi.sound(ent, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/damage.wav"), 1, Defines.ATTN_NORM, 0); } }; static ItemUseAdapter Use_Invulnerability = new ItemUseAdapter() { public String getID() { return "use_invulnerability";} public void use(edict_t ent, gitem_t item) { ent.client.pers.inventory[ITEM_INDEX(item)]--; GameUtil.ValidateSelectedItem(ent); if (ent.client.invincible_framenum > GameBase.level.framenum) ent.client.invincible_framenum += 300; else ent.client.invincible_framenum = GameBase.level.framenum + 300; GameBase.gi.sound(ent, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/protect.wav"), 1, Defines.ATTN_NORM, 0); } }; static ItemUseAdapter Use_Breather = new ItemUseAdapter() { public String getID() { return "use_breather";} public void use(edict_t ent, gitem_t item) { ent.client.pers.inventory[ITEM_INDEX(item)]--; GameUtil.ValidateSelectedItem(ent); if (ent.client.breather_framenum > GameBase.level.framenum) ent.client.breather_framenum += 300; else ent.client.breather_framenum = GameBase.level.framenum + 300; GameBase.gi.sound(ent, Defines.CHAN_ITEM, GameBase.gi .soundindex("items/damage.wav"), 1, Defines.ATTN_NORM, 0); } }; static ItemUseAdapter Use_Envirosuit = new ItemUseAdapter() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -