Merge pull request #1716 from Dune-jr/feature-damage-netevent

Add Damage net event
This commit is contained in:
oy 2018-11-30 17:00:30 +01:00 committed by GitHub
commit c58510c345
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 49 deletions

View file

@ -231,8 +231,12 @@ Objects = [
NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'), NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'),
]), ]),
NetEvent("DamageInd:Common", [ NetEvent("Damage:Common", [ # Unused yet
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
NetIntAny("m_Angle"), NetIntAny("m_Angle"),
NetIntRange("m_HealthAmount", 1, 9),
NetIntRange("m_ArmorAmount", 1, 9),
NetBool("m_Self"),
]), ]),
] ]

View file

@ -22,6 +22,8 @@ CEffects::CEffects()
{ {
m_Add50hz = false; m_Add50hz = false;
m_Add100hz = false; m_Add100hz = false;
m_DamageTaken = 0;
m_DamageTakenTick = 0;
} }
void CEffects::AirJump(vec2 Pos) void CEffects::AirJump(vec2 Pos)
@ -47,9 +49,32 @@ void CEffects::AirJump(vec2 Pos)
m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos);
} }
void CEffects::DamageIndicator(vec2 Pos, vec2 Dir) void CEffects::DamageIndicator(vec2 Pos, int Amount)
{ {
m_pClient->m_pDamageind->Create(Pos, Dir); m_DamageTaken++;
int Angle;
// create healthmod indicator
if(Client()->LocalTime() < m_DamageTakenTick+0.5f)
{
// make sure that the damage indicators don't group together
Angle = m_DamageTaken*0.25f;
}
else
{
m_DamageTaken = 0;
Angle = 0;
}
float a = 3*pi/2 + Angle;
float s = a-pi/3;
float e = a+pi/3;
for(int i = 0; i < Amount; i++)
{
float f = mix(s, e, float(i+1)/float(Amount+2));
m_pClient->m_pDamageind->Create(vec2(Pos.x, Pos.y), direction(f));
}
m_DamageTakenTick = Client()->LocalTime();
} }
void CEffects::PowerupShine(vec2 Pos, vec2 size) void CEffects::PowerupShine(vec2 Pos, vec2 size)

View file

@ -8,6 +8,9 @@ class CEffects : public CComponent
{ {
bool m_Add50hz; bool m_Add50hz;
bool m_Add100hz; bool m_Add100hz;
int m_DamageTaken;
float m_DamageTakenTick;
public: public:
CEffects(); CEffects();
@ -19,7 +22,7 @@ public:
void Explosion(vec2 Pos); void Explosion(vec2 Pos);
void HammerHit(vec2 Pos); void HammerHit(vec2 Pos);
void AirJump(vec2 Pos); void AirJump(vec2 Pos);
void DamageIndicator(vec2 Pos, vec2 Dir); void DamageIndicator(vec2 Pos, int Amount);
void PlayerSpawn(vec2 Pos); void PlayerSpawn(vec2 Pos);
void PlayerDeath(vec2 Pos, int ClientID); void PlayerDeath(vec2 Pos, int ClientID);
void PowerupShine(vec2 Pos, vec2 Size); void PowerupShine(vec2 Pos, vec2 Size);

View file

@ -820,10 +820,10 @@ void CGameClient::ProcessEvents()
IClient::CSnapItem Item; IClient::CSnapItem Item;
const void *pData = Client()->SnapGetItem(SnapType, Index, &Item); const void *pData = Client()->SnapGetItem(SnapType, Index, &Item);
if(Item.m_Type == NETEVENTTYPE_DAMAGEIND) if(Item.m_Type == NETEVENTTYPE_DAMAGE)
{ {
CNetEvent_DamageInd *ev = (CNetEvent_DamageInd *)pData; CNetEvent_Damage *ev = (CNetEvent_Damage *)pData;
m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), direction(ev->m_Angle/256.0f)); m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), ev->m_HealthAmount + ev->m_ArmorAmount);
} }
else if(Item.m_Type == NETEVENTTYPE_EXPLOSION) else if(Item.m_Type == NETEVENTTYPE_EXPLOSION)
{ {

View file

@ -187,7 +187,7 @@ void CCharacter::HandleNinja()
if(m_NumObjectsHit < 10) if(m_NumObjectsHit < 10)
m_apHitObjects[m_NumObjectsHit++] = aEnts[i]; m_apHitObjects[m_NumObjectsHit++] = aEnts[i];
aEnts[i]->TakeDamage(vec2(0, -10.0f), g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, m_pPlayer->GetCID(), WEAPON_NINJA); aEnts[i]->TakeDamage(vec2(0, -10.0f), m_Ninja.m_ActivationDir*-1, g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, m_pPlayer->GetCID(), WEAPON_NINJA);
} }
} }
@ -320,7 +320,7 @@ void CCharacter::FireWeapon()
else else
Dir = vec2(0.f, -1.f); Dir = vec2(0.f, -1.f);
pTarget->TakeDamage(vec2(0.f, -1.f) + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f, g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, pTarget->TakeDamage(vec2(0.f, -1.f) + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f, Dir*-1, g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage,
m_pPlayer->GetCID(), m_ActiveWeapon); m_pPlayer->GetCID(), m_ActiveWeapon);
Hits++; Hits++;
} }
@ -620,7 +620,6 @@ void CCharacter::TickDefered()
void CCharacter::TickPaused() void CCharacter::TickPaused()
{ {
++m_AttackTick; ++m_AttackTick;
++m_DamageTakenTick;
++m_Ninja.m_ActivationTick; ++m_Ninja.m_ActivationTick;
++m_ReckoningTick; ++m_ReckoningTick;
if(m_LastAction != -1) if(m_LastAction != -1)
@ -679,7 +678,7 @@ void CCharacter::Die(int Killer, int Weapon)
GameServer()->CreateDeath(m_Pos, m_pPlayer->GetCID()); GameServer()->CreateDeath(m_Pos, m_pPlayer->GetCID());
} }
bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) bool CCharacter::TakeDamage(vec2 Force, vec2 Source, int Dmg, int From, int Weapon)
{ {
m_Core.m_Vel += Force; m_Core.m_Vel += Force;
@ -690,20 +689,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
if(From == m_pPlayer->GetCID()) if(From == m_pPlayer->GetCID())
Dmg = max(1, Dmg/2); Dmg = max(1, Dmg/2);
m_DamageTaken++; int OldHealth = m_Health, OldArmor = m_Armor;
// create healthmod indicator
if(Server()->Tick() < m_DamageTakenTick+25)
{
// make sure that the damage indicators doesn't group together
GameServer()->CreateDamageInd(m_Pos, m_DamageTaken*0.25f, Dmg);
}
else
{
m_DamageTaken = 0;
GameServer()->CreateDamageInd(m_Pos, 0, Dmg);
}
if(Dmg) if(Dmg)
{ {
if(m_Armor) if(m_Armor)
@ -729,7 +715,8 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
m_Health -= Dmg; m_Health -= Dmg;
} }
m_DamageTakenTick = Server()->Tick(); // create healthmod indicator
GameServer()->CreateDamage(m_Pos, m_pPlayer->GetCID(), Source, OldHealth-m_Health, OldArmor-m_Armor, From == m_pPlayer->GetCID());
// do damage Hit sound // do damage Hit sound
if(From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From]) if(From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From])

View file

@ -42,7 +42,7 @@ public:
void FireWeapon(); void FireWeapon();
void Die(int Killer, int Weapon); void Die(int Killer, int Weapon);
bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon); bool TakeDamage(vec2 Force, vec2 Source, int Dmg, int From, int Weapon);
bool Spawn(class CPlayer *pPlayer, vec2 Pos); bool Spawn(class CPlayer *pPlayer, vec2 Pos);
bool Remove(); bool Remove();
@ -83,8 +83,6 @@ private:
int m_ReloadTimer; int m_ReloadTimer;
int m_AttackTick; int m_AttackTick;
int m_DamageTaken;
int m_EmoteType; int m_EmoteType;
int m_EmoteStop; int m_EmoteStop;
@ -101,8 +99,6 @@ private:
int m_NumInputs; int m_NumInputs;
int m_Jumped; int m_Jumped;
int m_DamageTakenTick;
int m_Health; int m_Health;
int m_Armor; int m_Armor;

View file

@ -30,7 +30,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
m_From = From; m_From = From;
m_Pos = At; m_Pos = At;
m_Energy = -1; m_Energy = -1;
pHit->TakeDamage(vec2(0.f, 0.f), g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Damage, m_Owner, WEAPON_LASER); pHit->TakeDamage(vec2(0.f, 0.f), normalize(To-From), g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Damage, m_Owner, WEAPON_LASER);
return true; return true;
} }

View file

@ -76,7 +76,7 @@ void CProjectile::Tick()
GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, m_Damage); GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, m_Damage);
else if(TargetChr) else if(TargetChr)
TargetChr->TakeDamage(m_Direction * max(0.001f, m_Force), m_Damage, m_Owner, m_Weapon); TargetChr->TakeDamage(m_Direction * max(0.001f, m_Force), m_Direction*-1, m_Damage, m_Owner, m_Weapon);
GameServer()->m_World.DestroyEntity(this); GameServer()->m_World.DestroyEntity(this);
} }

View file

@ -93,22 +93,19 @@ class CCharacter *CGameContext::GetPlayerChar(int ClientID)
return m_apPlayers[ClientID]->GetCharacter(); return m_apPlayers[ClientID]->GetCharacter();
} }
void CGameContext::CreateDamageInd(vec2 Pos, float Angle, int Amount) void CGameContext::CreateDamage(vec2 Pos, int Id, vec2 Source, int HealthAmount, int ArmorAmount, bool Self)
{ {
float a = 3*pi/2 + Angle; float f = angle(Source);
//float a = get_angle(dir); CNetEvent_Damage *pEvent = (CNetEvent_Damage *)m_Events.Create(NETEVENTTYPE_DAMAGE, sizeof(CNetEvent_Damage));
float s = a-pi/3; if(pEvent)
float e = a+pi/3;
for(int i = 0; i < Amount; i++)
{ {
float f = mix(s, e, float(i+1)/float(Amount+2)); pEvent->m_X = (int)Pos.x;
CNetEvent_DamageInd *pEvent = (CNetEvent_DamageInd *)m_Events.Create(NETEVENTTYPE_DAMAGEIND, sizeof(CNetEvent_DamageInd)); pEvent->m_Y = (int)Pos.y;
if(pEvent) pEvent->m_ClientID = Id;
{ pEvent->m_Angle = (int)(f*256.0f);
pEvent->m_X = (int)Pos.x; pEvent->m_HealthAmount = HealthAmount;
pEvent->m_Y = (int)Pos.y; pEvent->m_ArmorAmount = ArmorAmount;
pEvent->m_Angle = (int)(f*256.0f); pEvent->m_Self = Self;
}
} }
} }
@ -149,7 +146,7 @@ void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamag
Force = normalize(Diff) * MaxForce; Force = normalize(Diff) * MaxForce;
float Factor = 1 - clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f); float Factor = 1 - clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f);
if((int)(Factor * MaxDamage)) if((int)(Factor * MaxDamage))
apEnts[i]->TakeDamage(Force * Factor, (int)(Factor * MaxDamage), Owner, Weapon); apEnts[i]->TakeDamage(Force * Factor, Diff*-1, (int)(Factor * MaxDamage), Owner, Weapon);
} }
} }

View file

@ -124,7 +124,7 @@ public:
CVoteOptionServer *m_pVoteOptionLast; CVoteOptionServer *m_pVoteOptionLast;
// helper functions // helper functions
void CreateDamageInd(vec2 Pos, float AngleMod, int Amount); void CreateDamage(vec2 Pos, int Id, vec2 Source, int HealthAmount, int ArmorAmount, bool Self);
void CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamage); void CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamage);
void CreateHammerHit(vec2 Pos); void CreateHammerHit(vec2 Pos);
void CreatePlayerSpawn(vec2 Pos); void CreatePlayerSpawn(vec2 Pos);