From: Kenny G. <ken...@us...> - 2007-09-10 07:55:18
|
Update of /cvsroot/planeshift/planeshift/src/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26271/src/server Modified Files: client.cpp client.h combatmanager.cpp combatmanager.h gem.cpp gem.h usermanager.cpp usermanager.h Log Message: - Initial implementation of non-deathmatch duels. Now, instead of killing a player, you'll simply defeat them/knock them down when their health reaches zero, If you strike them when they're down, you'll kill them - otherwise, they're automatically released after 30 seconds. => NETVERSION BUMPED! Index: client.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/client.cpp,v retrieving revision 1.136 retrieving revision 1.137 diff -C2 -d -r1.136 -r1.137 *** client.cpp 23 Jun 2007 17:38:31 -0000 1.136 --- client.cpp 10 Sep 2007 07:55:16 -0000 1.137 *************** *** 135,141 **** return true; ! ! ! return !(GetActor()->GetMode() == PSCHARACTER_MODE_SPELL_CASTING || GetActor()->GetMode() == PSCHARACTER_MODE_COMBAT); } --- 135,139 ---- return true; ! return !(GetActor()->GetMode() == PSCHARACTER_MODE_SPELL_CASTING || GetActor()->GetMode() == PSCHARACTER_MODE_COMBAT || GetActor()->GetMode() == PSCHARACTER_MODE_DEFEATED); } *************** *** 257,268 **** } ! void Client::RemoveDuelClient(int clientnum) { ! size_t i; ! for (i=0; i<duel_clients.GetSize(); i++) { ! if (duel_clients[i] == clientnum) ! duel_clients.DeleteIndex(i); } } --- 255,280 ---- } ! void Client::RemoveDuelClient(Client *client) { ! if (actor) ! actor->RemoveAttackerHistory(client->GetActor()); ! duel_clients.Delete(client->GetClientNum()); ! } ! ! void Client::ClearAllDuelClients() ! { ! for (int i = 0; i < GetDuelClientCount(); i++) { ! Client *duelClient = psserver->GetConnections()->Find(duel_clients[i]); ! if (duelClient) ! { ! // Also remove us from their list. ! duelClient->RemoveDuelClient(this); ! ! if (actor) ! actor->RemoveAttackerHistory(duelClient->GetActor()); ! } } + duel_clients.Empty(); } *************** *** 279,289 **** bool Client::IsDuelClient(int clientnum) { ! size_t i; ! for (i=0; i<duel_clients.GetSize(); i++) { ! if (duel_clients[i] == clientnum) ! return true; } - return false; } --- 291,312 ---- bool Client::IsDuelClient(int clientnum) { ! return (duel_clients.Find(clientnum) != csArrayItemNotFound); ! } ! ! void Client::AnnounceToDuelClients(gemActor *attacker, const char *event) ! { ! psserver->SendSystemOK(clientnum, "You've been %s by %s!", event, attacker->GetName()); ! for (size_t i = 0; i < duel_clients.GetSize(); i++) { ! int duelClientID = duel_clients[i]; ! Client *duelClient = psserver->GetConnections()->Find(duelClientID); ! if (duelClient) ! { ! if (duelClientID == attacker->GetClientID()) ! psserver->SendSystemOK(duelClientID, "You've %s %s!", event, GetName()); ! else ! psserver->SendSystemOK(duelClientID, "%s has %s %s!", attacker->GetName(), event, GetName()); ! } } } Index: client.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/client.h,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** client.h 2 Sep 2007 21:32:49 -0000 1.102 --- client.h 10 Sep 2007 07:55:16 -0000 1.103 *************** *** 285,292 **** void AddDuelClient(int clientnum); ! void RemoveDuelClient(int clientnum); int GetDuelClientCount(); int GetDuelClient(int id); bool IsDuelClient(int clientnum); // Flood stuff --- 285,294 ---- void AddDuelClient(int clientnum); ! void RemoveDuelClient(Client *client); ! void ClearAllDuelClients(); int GetDuelClientCount(); int GetDuelClient(int id); bool IsDuelClient(int clientnum); + void AnnounceToDuelClients(gemActor *attacker, const char* event); // Flood stuff Index: combatmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/combatmanager.cpp,v retrieving revision 1.153 retrieving revision 1.154 diff -C2 -d -r1.153 -r1.154 *** combatmanager.cpp 2 Sep 2007 23:19:58 -0000 1.153 --- combatmanager.cpp 10 Sep 2007 07:55:16 -0000 1.154 *************** *** 257,260 **** --- 257,263 ---- psCharacter *attacker_character = attacker->GetCharacterData(); + if (attacker_character->GetMode() == PSCHARACTER_MODE_DEFEATED) + return; + if (attacker_character->GetMode() == PSCHARACTER_MODE_COMBAT) // Already fighting { *************** *** 866,869 **** --- 869,875 ---- Debug1(LOG_COMBAT,death.deadActor->GetClientID(),"Combat Manager handling Death Event\n"); + // Stop any duels. + death.deadActor->GetClient()->ClearAllDuelClients(); + // Stop actor moving. death.deadActor->StopMoving(); *************** *** 885,889 **** --- 891,912 ---- /*-------------------------------------------------------------*/ + psSpareDefeatedEvent::psSpareDefeatedEvent(gemActor *losr, gemActor *winner) : psGameEvent(0, SECONDS_BEFORE_SPARING_DEFEATED * 1000, "psSpareDefeatedEvent") + { + loser = losr->GetClient(); + winnerClientID = winner->GetClientID(); + } + void psSpareDefeatedEvent::Trigger() + { + // Ignore stale events: perhaps the character was already killed and resurrected... + if (!loser.IsValid() || !loser->GetActor() || loser->GetActor()->GetMode() != PSCHARACTER_MODE_DEFEATED) + return; + + psserver->SendSystemInfo(loser->GetClientNum(), "Your opponent has spared your life."); + loser->ClearAllDuelClients(); + loser->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); + } + + /*-------------------------------------------------------------*/ psCombatGameEvent::psCombatGameEvent(psCombatManager *mgr, Index: combatmanager.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/combatmanager.h,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** combatmanager.h 2 Sep 2007 23:19:58 -0000 1.43 --- combatmanager.h 10 Sep 2007 07:55:17 -0000 1.44 *************** *** 25,28 **** --- 25,30 ---- #include "msgmanager.h" + #define SECONDS_BEFORE_SPARING_DEFEATED 30 + class MathScriptVar; class psCombatGameEvent; *************** *** 121,124 **** --- 123,136 ---- }; + class psSpareDefeatedEvent : public psGameEvent + { + protected: + csWeakRef<Client> loser; + int winnerClientID; + + public: + psSpareDefeatedEvent(gemActor *losr, gemActor *winner); + void Trigger(); + }; #endif Index: gem.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/gem.cpp,v retrieving revision 1.478 retrieving revision 1.479 diff -C2 -d -r1.478 -r1.479 *** gem.cpp 8 Sep 2007 19:12:20 -0000 1.478 --- gem.cpp 10 Sep 2007 07:55:17 -0000 1.479 *************** *** 105,108 **** --- 105,109 ---- #include "adminmanager.h" #include "commandmanager.h" + #include "combatmanager.h" // #define PSPROXDEBUG *************** *** 1995,2001 **** evt.FireEvent(); } ! // Death takes some special work ! if ( fabs(hp) < 0.0005f ) // check for dead { // If no explicit killer, look for the last person to cast a DoT spell. --- 1996,2002 ---- evt.FireEvent(); } ! // Death takes some special work ! if (fabs(hp) < 0.0005f || GetMode() == PSCHARACTER_MODE_DEFEATED) // check for dead { // If no explicit killer, look for the last person to cast a DoT spell. *************** *** 2011,2019 **** } } ! psDeathEvent death(this,attacker); ! death.FireEvent(); ! SetMode(PSCHARACTER_MODE_DEAD); ! if (attacker != NULL && attacker->IsAlive()) attacker->SetMode(PSCHARACTER_MODE_PEACE); } --- 2012,2036 ---- } } ! // If in a duel, don't immediately kill...defeat. ! if (attacker && GetMode() != PSCHARACTER_MODE_DEFEATED && GetClient() && GetClient()->IsDuelClient(attacker->GetClientID())) ! { ! // Auto-unlock after a few seconds if not explicitly killed first ! psSpareDefeatedEvent *evt = new psSpareDefeatedEvent(this, attacker); ! psserver->GetEventManager()->Push(evt); ! SetMode(PSCHARACTER_MODE_DEFEATED); ! ! GetClient()->AnnounceToDuelClients(attacker, "defeated"); ! } ! else ! { ! psDeathEvent death(this, attacker); ! death.FireEvent(); ! if (GetMode() == PSCHARACTER_MODE_DEFEATED && attacker) ! GetClient()->AnnounceToDuelClients(attacker, "slain"); ! SetMode(PSCHARACTER_MODE_DEAD); ! } ! ! if (attacker && attacker->IsAlive()) attacker->SetMode(PSCHARACTER_MODE_PEACE); } *************** *** 2051,2054 **** --- 2068,2084 ---- } + void gemActor::RemoveAttackerHistory(gemActor * attacker) + { + if (attacker && dmgHistory.GetSize() > 0) + { + // Count backwards to avoid trouble with shifting indexes + for (size_t i = dmgHistory.GetSize() - 1; i != (size_t) -1; i--) + { + if (dmgHistory[i]->attacker_ref == attacker) + dmgHistory.DeleteIndex(i); + } + } + } + void gemActor::UpdateStats() { Index: gem.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/gem.h,v retrieving revision 1.204 retrieving revision 1.205 diff -C2 -d -r1.204 -r1.205 *** gem.h 2 Sep 2007 21:32:49 -0000 1.204 --- gem.h 10 Sep 2007 07:55:17 -0000 1.205 *************** *** 602,605 **** --- 602,606 ---- void DoDamage(gemActor *attacker, float damage, float damageRate = 0.0f, csTicks duration=0); void AddAttackerHistory(gemActor * attacker, float damage, float damageRate = 0.0f, csTicks duration = 0 ); + void RemoveAttackerHistory(gemActor * attacker); void Kill(gemActor *attacker) { DoDamage(attacker, psChar->GetHP() ); } void Resurrect(); *************** *** 883,886 **** }; - #endif --- 884,886 ---- Index: usermanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/usermanager.cpp,v retrieving revision 1.316 retrieving revision 1.317 diff -C2 -d -r1.316 -r1.317 *** usermanager.cpp 2 Sep 2007 23:19:59 -0000 1.316 --- usermanager.cpp 10 Sep 2007 07:55:17 -0000 1.317 *************** *** 125,129 **** psserver->GetEventManager()->Subscribe(this,MSGTYPE_CHARDESCUPDATE,REQUIRE_READY_CLIENT); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_DEATH_EVENT,NO_VALIDATION); psserver->GetEventManager()->Subscribe(this,MSGTYPE_TARGET_EVENT,NO_VALIDATION); psserver->GetEventManager()->Subscribe(this,MSGTYPE_ENTRANCE,REQUIRE_READY_CLIENT); --- 125,128 ---- *************** *** 139,143 **** psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CHARDESCUPDATE); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_DEATH_EVENT); psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_TARGET_EVENT); psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_ENTRANCE); --- 138,141 ---- *************** *** 622,683 **** } - void UserManager::HandleDeathEvent(MsgEntry *me) - { - Debug1(LOG_COMBAT, 0,"UserManager handling Death Event\n"); - // UserManager only stops duels and awards credits on death events - psDeathEvent evt(me); - - Client *loser=NULL,*winner=NULL; - loser = clients->Find( evt.deadActor->GetClientID() ); - - if(evt.killer) - winner = clients->Find( evt.killer->GetClientID() ); - - csString loserName("None"); - csString winnerName("the world"); - - if(loser && loser->GetActor()) - loserName = loser->GetName(); - - if(winner && winner->GetActor()) - winnerName = winner->GetName(); - - csString info; - if ( loser == winner ) - { - info.Format("%s has just killed themself", loserName.GetData()); - } - else - { - info.Format("%s has just been killed by %s", loserName.GetData(), winnerName.GetData()); - } - - // Remove every attacker - if (loser) - { - for(int i = loser->GetDuelClientCount()-1; i >= 0;i--) - { - Client* client = clients->Find(loser->GetDuelClient(i)); - if(!client) - { - loser->RemoveDuelClient(loser->GetDuelClient(i)); - continue; - } - - if(client != winner) - { - psserver->SendSystemInfo(client->GetClientNum(),info); - } - StopDuel(loser, client); - - if(loser->GetTargetObject() == client->GetActor()) - { - // Stop attacking if we are attacking the killed one - psserver->combatmanager->StopAttack(loser->GetActor()); - } - } - } - } - void UserManager::HandleTargetEvent(MsgEntry *me) { --- 620,623 ---- *************** *** 862,870 **** break; } - case MSGTYPE_DEATH_EVENT: - { - HandleDeathEvent(me); - break; - } case MSGTYPE_TARGET_EVENT: { --- 802,805 ---- *************** *** 1813,1819 **** { // Remove the duel from both sides. ! loser->RemoveDuelClient(winner->GetClientNum() ); loser->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); ! winner->RemoveDuelClient(loser->GetClientNum()); winner->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); psserver->SendSystemOK(winner->GetClientNum(),"You've won the duel against %s!",loser->GetName()); --- 1748,1754 ---- { // Remove the duel from both sides. ! loser->RemoveDuelClient(winner); loser->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); ! winner->RemoveDuelClient(loser); winner->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); psserver->SendSystemOK(winner->GetClientNum(),"You've won the duel against %s!",loser->GetName()); Index: usermanager.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/usermanager.h,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** usermanager.h 2 Sep 2007 23:19:59 -0000 1.67 --- usermanager.h 10 Sep 2007 07:55:17 -0000 1.68 *************** *** 292,296 **** void HandleMOTDRequest(MsgEntry *me,Client *client); void HandleUserCommand(MsgEntry *me,Client *client); - void HandleDeathEvent(MsgEntry *me); void HandleCharDescUpdate(MsgEntry *me,Client *client); void HandleCharDetailsRequest(MsgEntry *me,Client *client); --- 292,295 ---- |