Some network fixes with sidearm

This commit is contained in:
viktorljung
2016-03-12 17:34:32 +01:00
parent f7363eeea4
commit 944d10f4bb
2 changed files with 45 additions and 43 deletions
@@ -14,6 +14,7 @@ bool MultiplayerSnapshotFilter::FilterComponent(EntityWrapper entity, SharedComp
|| component.Info.Name == "Physics"
|| component.Info.Name == "AssaultWeapon"
|| component.Info.Name == "DefenderWeapon"
|| component.Info.Name == "SidearmWeapon"
|| component.Info.Name == "Animation"
|| component.Info.Name == "Blend"
|| component.Info.Name == "BlendAdditive"
+44 -43
View File
@@ -8,51 +8,52 @@ BoostSystem::BoostSystem(SystemParams params)
bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e)
{
if (e.Victim.ID == e.Inflictor.ID) {
return false;
}
if (!IsClient) {
if (!e.Victim.Valid() || !LocalPlayer.Valid()) {
return false;
}
if (e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) {
return false;
}
if (!e.Inflictor.Valid()) {
return false;
}
//if its not friendly fire, return
if ((int)m_World->GetComponent(e.Inflictor.ID, "Team")["Team"] != (int)m_World->GetComponent(e.Victim.ID, "Team")["Team"]) {
return false;
}
//determine the inflictors class
auto className = DetermineClass(e.Inflictor);
if (className == "") {
return false;
}
LOG_INFO("intflictor: %s, vicitm: %s", e.Inflictor.Name().c_str(), e.Victim.Name().c_str());
if(className == "SidearmWeapon") { // give ammo
giveAmmo(e.Inflictor, e.Victim);
} else { //give boost
//get the XML file, example: "Schema/Entities/BoostclassName.xml"
std::string classXML = "Schema/Entities/" + className + ".xml";
//check if player already has a child with the component, if so delete that child
auto playerBoostAssaultEntity = e.Victim.FirstChildByName(className);
if (playerBoostAssaultEntity.Valid()) {
m_World->DeleteEntity(playerBoostAssaultEntity.ID);
if (e.Victim.ID == e.Inflictor.ID) {
return false;
}
if (!e.Victim.Valid() || !LocalPlayer.Valid()) {
return false;
}
if (e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) {
return false;
}
if (!e.Inflictor.Valid()) {
return false;
}
//if its not friendly fire, return
if ((int)m_World->GetComponent(e.Inflictor.ID, "Team")["Team"] != (int)m_World->GetComponent(e.Victim.ID, "Team")["Team"]) {
return false;
}
//determine the inflictors class
auto className = DetermineClass(e.Inflictor);
if (className == "") {
return false;
}
if (className == "SidearmWeapon") { // give ammo
giveAmmo(e.Inflictor, e.Victim);
} else { //give boost
//get the XML file, example: "Schema/Entities/BoostclassName.xml"
std::string classXML = "Schema/Entities/" + className + ".xml";
//check if player already has a child with the component, if so delete that child
auto playerBoostAssaultEntity = e.Victim.FirstChildByName(className);
if (playerBoostAssaultEntity.Valid()) {
m_World->DeleteEntity(playerBoostAssaultEntity.ID);
}
//load boost XML file, set it entity parented with the victim player
auto entityFile = ResourceManager::Load<EntityFile>(classXML);
EntityWrapper boostAssaultEntity = entityFile->MergeInto(m_World);
m_World->SetName(boostAssaultEntity.ID, className);
m_World->SetParent(boostAssaultEntity.ID, e.Victim.ID);
}
//load boost XML file, set it entity parented with the victim player
auto entityFile = ResourceManager::Load<EntityFile>(classXML);
EntityWrapper boostAssaultEntity = entityFile->MergeInto(m_World);
m_World->SetName(boostAssaultEntity.ID, className);
m_World->SetParent(boostAssaultEntity.ID, e.Victim.ID);
}
return true;