|
2 | 2 |
|
3 | 3 | #define CLIGHTNING_MAX_HOPS 4 |
4 | 4 |
|
| 5 | +void lightningstorm_sound(edict_t* self); |
| 6 | + |
5 | 7 | void G_SpawnParticleTrail (vec3_t start, vec3_t end, int particles, int color) |
6 | 8 | { |
7 | 9 | int i, spacing; |
@@ -64,6 +66,170 @@ qboolean ChainLightning_Attack (edict_t *ent, edict_t *target, int damage, int m |
64 | 66 | return result; |
65 | 67 | } |
66 | 68 |
|
| 69 | +void CL_attack(edict_t* self, edict_t *target, int damage) |
| 70 | +{ |
| 71 | + //if (G_ValidTarget(self, target, true, false)) |
| 72 | + //{ |
| 73 | + // do less damage to corpses |
| 74 | + if (target->health < 1 && damage > 100) |
| 75 | + damage = 100; |
| 76 | + //gi.dprintf("CL did %d damage at %d\n", damage, (int)level.framenum); |
| 77 | + // deal damage |
| 78 | + T_Damage(target, self, self, vec3_origin, target->s.origin, vec3_origin, damage, 0, DAMAGE_ENERGY, MOD_LIGHTNING); |
| 79 | + //return true; |
| 80 | + //} |
| 81 | + //return false; |
| 82 | +} |
| 83 | + |
| 84 | +qboolean CL_targetinlist(edict_t* self, edict_t *target) |
| 85 | +{ |
| 86 | + for (int i = 0; i < self->monsterinfo.target_index; i++) |
| 87 | + { |
| 88 | + if (target == self->monsterinfo.dmglist[i].player) |
| 89 | + return true; |
| 90 | + } |
| 91 | + return false; |
| 92 | +} |
| 93 | + |
| 94 | +edict_t *CL_findtarget(edict_t* self, vec3_t org, float radius, qboolean check_list) |
| 95 | +{ |
| 96 | + edict_t* e = NULL; |
| 97 | + |
| 98 | + while ((e = findclosestradius(e, org, radius)) != NULL) |
| 99 | + { |
| 100 | + if (!G_ValidTarget(self, e, true, false)) |
| 101 | + continue; |
| 102 | + if (check_list && CL_targetinlist(self, e)) |
| 103 | + continue; |
| 104 | + return e; |
| 105 | + } |
| 106 | + return NULL; |
| 107 | +} |
| 108 | + |
| 109 | +void chainlightning_think(edict_t* self) |
| 110 | +{ |
| 111 | + edict_t *enemy = CL_findtarget(self, self->s.origin, self->monsterinfo.sight_range, true); |
| 112 | + |
| 113 | + if (self->light_level && enemy) // have ammo and valid target |
| 114 | + { |
| 115 | + vec3_t start; |
| 116 | + |
| 117 | + //gi.dprintf("%d: CL is attacking, ammo: %d\n", (int)level.framenum, self->light_level); |
| 118 | + // add enemy to the list so we don't attack the same target twice |
| 119 | + self->monsterinfo.dmglist[self->monsterinfo.target_index++].player = enemy; |
| 120 | + |
| 121 | + CL_attack(self, enemy, self->dmg); |
| 122 | + // move |
| 123 | + G_EntMidPoint(enemy, start); |
| 124 | + VectorCopy(start, self->s.origin); |
| 125 | + gi.linkentity(self); |
| 126 | + |
| 127 | + // lightning graphical effect |
| 128 | + gi.WriteByte(svc_temp_entity); |
| 129 | + gi.WriteByte(TE_HEATBEAM); |
| 130 | + gi.WriteShort(self - g_edicts); |
| 131 | + gi.WritePosition(self->s.old_origin); |
| 132 | + gi.WritePosition(self->s.origin); |
| 133 | + gi.multicast(self->s.origin, MULTICAST_PVS); |
| 134 | + |
| 135 | + VectorCopy(start, self->s.old_origin); |
| 136 | + |
| 137 | + // reduce ammo |
| 138 | + self->light_level--; |
| 139 | + // increase damage for next hop |
| 140 | + self->dmg *= CLIGHTNING_DMG_MOD; |
| 141 | + } |
| 142 | + else |
| 143 | + { |
| 144 | + //gi.dprintf("%d: CL is being removed, ammo: %d\n", (int)level.framenum, self->light_level); |
| 145 | + |
| 146 | + G_FreeEdict(self); |
| 147 | + return; |
| 148 | + } |
| 149 | + |
| 150 | + self->nextthink = level.time + FRAMETIME; |
| 151 | +} |
| 152 | + |
| 153 | +void fire_chainlightning(edict_t* self, vec3_t start, vec3_t aimdir, int damage, float radius, int attack_range, int hop_range, int max_hops) |
| 154 | +{ |
| 155 | + vec3_t end; |
| 156 | + edict_t* enemy = NULL; |
| 157 | + |
| 158 | + // calling entity made a sound, used to alert monsters |
| 159 | + self->lastsound = level.framenum; |
| 160 | + // play sound |
| 161 | + gi.sound(self, CHAN_ITEM, gi.soundindex("abilities/thunderbolt.wav"), 1, ATTN_NORM, 0); |
| 162 | + //lightningstorm_sound(self); |
| 163 | + |
| 164 | + // get ending position |
| 165 | + VectorMA(start, attack_range, aimdir, end); |
| 166 | + |
| 167 | + // trace from attacker to ending position |
| 168 | + trace_t tr = gi.trace(start, NULL, NULL, end, self, MASK_SHOT); |
| 169 | + |
| 170 | + //vec3_t org; |
| 171 | + // try to attack |
| 172 | + if (radius > 0) |
| 173 | + { |
| 174 | + edict_t* targ; |
| 175 | + if ((targ = CL_findtarget(self, tr.endpos, radius, false)) != NULL) |
| 176 | + { |
| 177 | + //FIXME: randomize endpos within the bbox of target |
| 178 | + CL_attack(self, targ, damage); |
| 179 | + enemy = targ; |
| 180 | + G_EntMidPoint(targ, end); |
| 181 | + end[0] = end[0] + GetRandom(0, (int)targ->maxs[0]) * crandom(); |
| 182 | + end[1] = end[1] + GetRandom(0, (int)targ->maxs[1]) * crandom(); |
| 183 | + // recalculate starting position directly above endpoint |
| 184 | + trace_t tr = gi.trace(end, NULL, NULL, tv(end[0], end[1], 8192), self, MASK_SOLID); |
| 185 | + VectorCopy(tr.endpos, start); |
| 186 | + } |
| 187 | + else |
| 188 | + VectorCopy(tr.endpos, end); |
| 189 | + } |
| 190 | + else if (G_ValidTarget(self, tr.ent, true, false)) |
| 191 | + { |
| 192 | + CL_attack(self, tr.ent, damage); |
| 193 | + enemy = tr.ent; |
| 194 | + VectorCopy(tr.endpos, end); |
| 195 | + } |
| 196 | + //else |
| 197 | + // return; |
| 198 | + |
| 199 | + // lightning graphical effect |
| 200 | + gi.WriteByte(svc_temp_entity); |
| 201 | + gi.WriteByte(TE_HEATBEAM); |
| 202 | + gi.WriteShort(self - g_edicts); |
| 203 | + gi.WritePosition(start); |
| 204 | + gi.WritePosition(end); |
| 205 | + gi.multicast(end, MULTICAST_PVS); |
| 206 | + |
| 207 | + if (!enemy) |
| 208 | + return; |
| 209 | + |
| 210 | + //gi.dprintf("%d: spawned CL ent\n", (int)level.framenum); |
| 211 | + // spawn lightning entity |
| 212 | + edict_t* lightning = G_Spawn(); |
| 213 | + lightning->classname = "lightning"; |
| 214 | + lightning->solid = SOLID_NOT; |
| 215 | + lightning->svflags |= SVF_NOCLIENT; |
| 216 | + lightning->owner = G_GetClient(self); // for lightning storm: to ensure the owner is the player, not the LS! |
| 217 | + //lightning->delay = level.time + duration; |
| 218 | + lightning->nextthink = level.time + FRAMETIME; |
| 219 | + lightning->think = chainlightning_think; |
| 220 | + VectorCopy(end, lightning->s.origin); |
| 221 | + VectorCopy(end, lightning->s.old_origin); |
| 222 | + VectorCopy(aimdir, lightning->movedir); |
| 223 | + lightning->dmg_radius = radius; |
| 224 | + lightning->dmg = damage * CLIGHTNING_DMG_MOD; // damage increases with each hop |
| 225 | + lightning->monsterinfo.sight_range = hop_range; |
| 226 | + lightning->light_level = max_hops; |
| 227 | + gi.linkentity(lightning); |
| 228 | + |
| 229 | + // add enemy to the list so we don't attack again |
| 230 | + lightning->monsterinfo.dmglist[lightning->monsterinfo.target_index++].player = enemy; |
| 231 | +} |
| 232 | + |
67 | 233 | void ChainLightning (edict_t *ent, vec3_t start, vec3_t aimdir, int damage, int attack_range, int hop_range) |
68 | 234 | { |
69 | 235 | int i=0, hops=CLIGHTNING_MAX_HOPS; |
@@ -201,9 +367,18 @@ void Cmd_ChainLightning_f (edict_t *ent, float skill_mult, float cost_mult) |
201 | 367 | VectorSet(offset, 0, 8, ent->viewheight-8); |
202 | 368 | P_ProjectSource(ent->client, ent->s.origin, offset, forward, right, start); |
203 | 369 |
|
204 | | - ChainLightning(ent, start, forward, damage, attack_range, hop_range); |
| 370 | + //ChainLightning(ent, start, forward, damage, attack_range, hop_range); |
| 371 | + fire_chainlightning(ent, start, forward, damage, 0, attack_range, hop_range, 4); |
205 | 372 |
|
206 | | - ent->client->ability_delay = level.time + CLIGHTNING_DELAY/* * cost_mult*/; |
| 373 | + //Talent: Wizardry - makes spell timer ability-specific instead of global |
| 374 | + int talentLevel = vrx_get_talent_level(ent, TALENT_WIZARDRY); |
| 375 | + if (talentLevel > 0) |
| 376 | + { |
| 377 | + ent->myskills.abilities[LIGHTNING].delay = level.time + CLIGHTNING_DELAY; |
| 378 | + ent->client->ability_delay = level.time + CLIGHTNING_DELAY * (1 - 0.2 * talentLevel); |
| 379 | + } |
| 380 | + else |
| 381 | + ent->client->ability_delay = level.time + CLIGHTNING_DELAY/* * cost_mult*/; |
207 | 382 | ent->client->pers.inventory[power_cube_index] -= cost; |
208 | 383 | } |
209 | 384 |
|
|
0 commit comments