mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge pull request #1716 from Dune-jr/feature-damage-netevent
Add Damage net event
This commit is contained in:
commit
c58510c345
|
@ -231,8 +231,12 @@ Objects = [
|
|||
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"),
|
||||
NetIntRange("m_HealthAmount", 1, 9),
|
||||
NetIntRange("m_ArmorAmount", 1, 9),
|
||||
NetBool("m_Self"),
|
||||
]),
|
||||
]
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ CEffects::CEffects()
|
|||
{
|
||||
m_Add50hz = false;
|
||||
m_Add100hz = false;
|
||||
m_DamageTaken = 0;
|
||||
m_DamageTakenTick = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -8,6 +8,9 @@ class CEffects : public CComponent
|
|||
{
|
||||
bool m_Add50hz;
|
||||
bool m_Add100hz;
|
||||
|
||||
int m_DamageTaken;
|
||||
float m_DamageTakenTick;
|
||||
public:
|
||||
CEffects();
|
||||
|
||||
|
@ -19,7 +22,7 @@ public:
|
|||
void Explosion(vec2 Pos);
|
||||
void HammerHit(vec2 Pos);
|
||||
void AirJump(vec2 Pos);
|
||||
void DamageIndicator(vec2 Pos, vec2 Dir);
|
||||
void DamageIndicator(vec2 Pos, int Amount);
|
||||
void PlayerSpawn(vec2 Pos);
|
||||
void PlayerDeath(vec2 Pos, int ClientID);
|
||||
void PowerupShine(vec2 Pos, vec2 Size);
|
||||
|
|
|
@ -820,10 +820,10 @@ void CGameClient::ProcessEvents()
|
|||
IClient::CSnapItem 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;
|
||||
m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), direction(ev->m_Angle/256.0f));
|
||||
CNetEvent_Damage *ev = (CNetEvent_Damage *)pData;
|
||||
m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), ev->m_HealthAmount + ev->m_ArmorAmount);
|
||||
}
|
||||
else if(Item.m_Type == NETEVENTTYPE_EXPLOSION)
|
||||
{
|
||||
|
|
|
@ -187,7 +187,7 @@ void CCharacter::HandleNinja()
|
|||
if(m_NumObjectsHit < 10)
|
||||
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
|
||||
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);
|
||||
Hits++;
|
||||
}
|
||||
|
@ -620,7 +620,6 @@ void CCharacter::TickDefered()
|
|||
void CCharacter::TickPaused()
|
||||
{
|
||||
++m_AttackTick;
|
||||
++m_DamageTakenTick;
|
||||
++m_Ninja.m_ActivationTick;
|
||||
++m_ReckoningTick;
|
||||
if(m_LastAction != -1)
|
||||
|
@ -679,7 +678,7 @@ void CCharacter::Die(int Killer, int Weapon)
|
|||
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;
|
||||
|
||||
|
@ -690,20 +689,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
|
|||
if(From == m_pPlayer->GetCID())
|
||||
Dmg = max(1, Dmg/2);
|
||||
|
||||
m_DamageTaken++;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
int OldHealth = m_Health, OldArmor = m_Armor;
|
||||
if(Dmg)
|
||||
{
|
||||
if(m_Armor)
|
||||
|
@ -729,7 +715,8 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
|
|||
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
|
||||
if(From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From])
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
void FireWeapon();
|
||||
|
||||
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 Remove();
|
||||
|
@ -83,8 +83,6 @@ private:
|
|||
int m_ReloadTimer;
|
||||
int m_AttackTick;
|
||||
|
||||
int m_DamageTaken;
|
||||
|
||||
int m_EmoteType;
|
||||
int m_EmoteStop;
|
||||
|
||||
|
@ -101,8 +99,6 @@ private:
|
|||
int m_NumInputs;
|
||||
int m_Jumped;
|
||||
|
||||
int m_DamageTakenTick;
|
||||
|
||||
int m_Health;
|
||||
int m_Armor;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
|
|||
m_From = From;
|
||||
m_Pos = At;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ void CProjectile::Tick()
|
|||
GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, m_Damage);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -93,22 +93,19 @@ class CCharacter *CGameContext::GetPlayerChar(int ClientID)
|
|||
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 a = get_angle(dir);
|
||||
float s = a-pi/3;
|
||||
float e = a+pi/3;
|
||||
for(int i = 0; i < Amount; i++)
|
||||
float f = angle(Source);
|
||||
CNetEvent_Damage *pEvent = (CNetEvent_Damage *)m_Events.Create(NETEVENTTYPE_DAMAGE, sizeof(CNetEvent_Damage));
|
||||
if(pEvent)
|
||||
{
|
||||
float f = mix(s, e, float(i+1)/float(Amount+2));
|
||||
CNetEvent_DamageInd *pEvent = (CNetEvent_DamageInd *)m_Events.Create(NETEVENTTYPE_DAMAGEIND, sizeof(CNetEvent_DamageInd));
|
||||
if(pEvent)
|
||||
{
|
||||
pEvent->m_X = (int)Pos.x;
|
||||
pEvent->m_Y = (int)Pos.y;
|
||||
pEvent->m_Angle = (int)(f*256.0f);
|
||||
}
|
||||
pEvent->m_X = (int)Pos.x;
|
||||
pEvent->m_Y = (int)Pos.y;
|
||||
pEvent->m_ClientID = Id;
|
||||
pEvent->m_Angle = (int)(f*256.0f);
|
||||
pEvent->m_HealthAmount = HealthAmount;
|
||||
pEvent->m_ArmorAmount = ArmorAmount;
|
||||
pEvent->m_Self = Self;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +146,7 @@ void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamag
|
|||
Force = normalize(Diff) * MaxForce;
|
||||
float Factor = 1 - clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
CVoteOptionServer *m_pVoteOptionLast;
|
||||
|
||||
// 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 CreateHammerHit(vec2 Pos);
|
||||
void CreatePlayerSpawn(vec2 Pos);
|
||||
|
|
Loading…
Reference in a new issue