ryuzayke | So basically I made this code for my game wich is for the fight stage..
This is the code the allow the player to be able to leave the fight, but once he leave the fight in type _PVM, the game think that the player is still in it so at the end at player still receive the ammount of experience for the combat when he shouldn't be getting it..
I know the text in english are not perfect -_- I'm french okay ?
Code :
- public void leftFight(Personnage perso, Personnage target)
- {
- if(perso == null)return;
- Fighter F = this.getFighterByPerso(perso);
- Fighter T = null;
- if(target != null) T = this.getFighterByPerso(target);
- if(ElinkEmu.CONFIG_DEBUG)
- {
- if(target != null && T != null)
- {
- GameServer.addToLog(perso.get_name()+" kick "+T.getPersonnage().get_name());
- }else
- {
- GameServer.addToLog(perso.get_name()+" has left the fight" );
- }
- }
- if(F != null)
- {
- switch(_type)
- {
- case Constants.FIGHT_TYPE_CHALLENGE: //challenges
- case Constants.FIGHT_TYPE_KOLI: //Arena
- case Constants.FIGHT_TYPE_AGRESSION: //PVP
- case Constants.FIGHT_TYPE_PVM: //PVM
- case Constants.FIGHT_TYPE_PVT: //Perco
- case Constants.FIGHT_TYPE_CONQUETE: //Prism
- if(_state >= Constants.FIGHT_STATE_ACTIVE)
- {
- if(_ordreJeu.size() == 0){
- endTurn();
- }else if(_ordreJeu.get(_curPlayer).getGUID() == F.getGUID())
- {
- endTurn();
- }
- onFighterDie(F, T);
- boolean StillInFight = false;
- if(_type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
- {
- StillInFight = verifyStillInFightTeam(F.getGUID());
- }else
- {
- StillInFight = verifyStillInFight();
- }
- if(!StillInFight) //If it stops here nobody left in the fight and the team
- {
- //puts an end to fighting
- verifIfTeamAllDead();
- }else
- {
- F.setLeft(true);
- SocketManager.GAME_SEND_ERASE_ON_MAP_TO_MAP(_map, F.getGUID());
- Personnage P = F.getPersonnage();
- P.set_duelID(-1);
- P.set_ready(false);
- //P.fullPDV(); //Put back life of the player when canceling a challenge.
- P.set_fight(null);
- P.setSitted(false);
- P.set_away(false);
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
- {
- /**Energy**/
- int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
- int Energy = P.get_energy() - EnergyLoos;
- if(Energy < 0) Energy = 0;
- P.set_energy(Energy);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
- /**Energy**/
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
- {
- int honor = P.get_honor()-500;
- if(honor < 0) honor = 0;
- P.set_honor(honor);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
- }
- try
- {
- Thread.sleep(1000);
- }catch(Exception E){};
- if(Energy == 0)
- {
- P.set_Ghosts();
- }else
- {
- P.warpToSavePos();
- P.set_PDV(1);
- }
- }
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- }
- }else if(_state == Constants.FIGHT_STATE_PLACE)
- {
- boolean isValid1 = false;
- if(T != null)
- {
- if(_init0 != null &&_init0.getPersonnage() != null)
- {
- if(F.getPersonnage().get_GUID() == _init0.getPersonnage().get_GUID())
- {
- isValid1 = true;
- }
- }
- if(_init1 != null &&_init1.getPersonnage() != null)
- {
- if(F.getPersonnage().get_GUID() == _init1.getPersonnage().get_GUID())
- {
- isValid1 = true;
- }
- }
- }
- if(isValid1) //Whoever does the action start the fight and leave another character
- {
- if((T.getTeam() == F.getTeam()) && (T.getGUID() != F.getGUID()))
- {
- if(ElinkEmu.CONFIG_DEBUG) System.out.println("Kick of : "+T.getPersonnage().get_name());
- SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, T.getPersonnage().get_GUID(), getTeamID(T.getGUID()));
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI) SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, T.getPersonnage().get_GUID(), getOtherTeamID(T.getGUID()));
- Personnage P = T.getPersonnage();
- P.set_duelID(-1);
- P.set_ready(false);
- P.fullPDV();
- P.set_fight(null);
- P.setSitted(false);
- P.set_away(false);
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- //We removes it from the team
- if(_team0.containsKey(T.getGUID()))
- {
- T._cell.removeFighter(T);
- _team0.remove(T.getGUID());
- }
- else if(_team1.containsKey(T.getGUID()))
- {
- T._cell.removeFighter(T);
- _team1.remove(T.getGUID());
- }
- for(Personnage z : _mapOld.getPersos()) FightStateAddFlag(this._mapOld, z);
- }
- }else if(T == null) //Leave it voluntarily so (T = null)
- {
- boolean isValid2 = false;
- if(_init0 != null &&_init0.getPersonnage() != null)
- {
- if(F.getPersonnage().get_GUID() == _init0.getPersonnage().get_GUID())
- {
- isValid2 = true;
- }
- }
- if(_init1 != null &&_init1.getPersonnage() != null)
- {
- if(F.getPersonnage().get_GUID() == _init1.getPersonnage().get_GUID())
- {
- isValid2 = true;
- }
- }
- if(isValid2) //He is going into battle => cancellation of the fight
- {
- for(Fighter f : this.getFighters(F.getTeam2()))
- {
- Personnage P = f.getPersonnage();
- P.set_duelID(-1);
- P.set_ready(false);
- //P.fullPDV();
- P.set_fight(null);
- P.setSitted(false);
- P.set_away(false);
- if(F.getPersonnage().get_GUID() != f.getPersonnage().get_GUID()) //Those who joined the fight go back on the map
- {
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- }else //Whoever did the fight dies loss + honor
- {
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
- {
- /**Energy**/
- int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
- int Energy = P.get_energy() - EnergyLoos;
- if(Energy < 0) Energy = 0;
- P.set_energy(Energy);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
- /**Energy**/
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
- {
- int honor = P.get_honor()-500;
- if(honor < 0) honor = 0;
- P.set_honor(honor);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
- }
- try
- {
- Thread.sleep(1000);
- }catch(Exception E){};
- if(Energy == 0)
- {
- P.set_Ghosts();
- }else
- {
- P.warpToSavePos();
- P.set_PDV(1);
- }
- }
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- }
- }
- _ticMyTimer_startTime = 0L;
- _ticMyTimer_endTurn = false;
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
- {
- for(Fighter f : this.getFighters(F.getOtherTeam()))
- {
- if(f.getPersonnage() == null) continue;
- Personnage P = f.getPersonnage();
- P.set_duelID(-1);
- P.set_ready(false);
- //P.fullPDV();
- P.set_fight(null);
- P.setSitted(false);
- P.set_away(false);
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- }
- }
- _state = 4; //Make sure we do not start the fight
- World.getCarte(_map.get_id()).removeFight(_id);
- SocketManager.GAME_SEND_MAP_FIGHT_COUNT_TO_MAP(World.getCarte(_map.get_id()));
- SocketManager.GAME_SEND_GAME_REMFLAG_PACKET_TO_MAP(this._mapOld,_init0.getGUID());
- if (_type == Constants.FIGHT_TYPE_CONQUETE) {
- String str = _Prisme.getCarte() + "|" + _Prisme.getX() + "|" + _Prisme.getY();
- for (Personnage z : World.getOnlinePersos()) {
- if (z == null)
- continue;
- if (z.get_align() != _Prisme.getalignement())
- continue;
- SocketManager.SEND_CS_SURVIVRE_MESSAGE_PRISME(z, str);
- }
- _Prisme.setInFight(-1);
- _Prisme.setFightID(-1);
- if (perso != null) {
- if (_Prisme != null)
- SocketManager.SEND_CP_INFO_DEFENSEURS_PRISME(perso, getDefenseurs());
- }
- for (Personnage z : World.getCarte((short) _Prisme.getCarte()).getPersos()) {
- if (z == null)
- continue;
- SocketManager.SEND_GM_PRISME_TO_MAP(z.get_compte().getGameThread().get_out(),
- z.get_curCarte());
- }
- }
- if(_type == Constants.FIGHT_TYPE_PVT)
- {
- for(Personnage z : World.getGuild(_guildID).getMembers())
- {
- if(z == null) continue;
- if(z.isOnline())
- {
- SocketManager.GAME_SEND_gITM_PACKET(z, Percepteur.parsetoGuild(z.get_guild().get_id()));
- SocketManager.GAME_SEND_PERCO_INFOS_PACKET(z, F._Perco, "S" );
- }
- }
- _perco.set_inFight((byte)0);
- _perco.set_inFightID((byte)-1);
- _perco.clearDefenseFight();
- for(Personnage z : World.getCarte((short)_perco.get_mapID()).getPersos())
- {
- if(z == null) continue;
- SocketManager.GAME_SEND_MAP_PERCO_GMS_PACKETS(z.get_compte().getGameThread().get_out(), z.get_curCarte());
- }
- }
- if(_type == Constants.FIGHT_TYPE_PVM)
- {
- int align = -1;
- if(_team1.size() >0)
- {
- _team1.get(_team1.keySet().toArray()[0]).getMob().getTemplate().getAlign();
- }
- //Si groupe non fixe
- if(!_mobGroup.isFix())World.getCarte(_map.get_id()).spawnGroup(align, 1, true,_mobGroup.getCellID()); //Respawn group
- }
- _map = null;
- _ordreJeu = null;
- }else //Either he joined the fight => Left to itself
- {
- SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, F.getPersonnage().get_GUID(), getTeamID(F.getGUID()));
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI) SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, F.getPersonnage().get_GUID(), getOtherTeamID(F.getGUID()));
- Personnage P = F.getPersonnage();
- P.set_duelID(-1);
- P.set_ready(false);
- //P.fullPDV();
- P.set_fight(null);
- P.setSitted(false);
- P.set_away(false);
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
- {
- /**Energy**/
- int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
- int Energy = P.get_energy() - EnergyLoos;
- if(Energy < 0) Energy = 0;
- P.set_energy(Energy);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
- /**Energy**/
- if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
- {
- int honor = P.get_honor()-500;
- if(honor < 0) honor = 0;
- P.set_honor(honor);
- if(P.isOnline())
- SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
- }
- try
- {
- Thread.sleep(1000);
- }catch(Exception E){};
- if(Energy == 0)
- {
- P.set_Ghosts();
- }else
- {
- P.warpToSavePos();
- P.set_PDV(1);
- }
- }
- if(P.isOnline())
- {
- try
- {
- Thread.sleep(200);
- }catch(Exception E){};
- SocketManager.GAME_SEND_GV_PACKET(P);
- P.refreshMapAfterFight();
- }
- //On le supprime de la team
- if(_team0.containsKey(F.getGUID()))
- {
- F._cell.removeFighter(F);
- _team0.remove(F.getGUID());
- }
- else if(_team1.containsKey(F.getGUID()))
- {
- F._cell.removeFighter(F);
- _team1.remove(F.getGUID());
- }
- for(Personnage z : _mapOld.getPersos()) FightStateAddFlag(this._mapOld, z);
- }
- }
- }else
- {
- if(ElinkEmu.CONFIG_DEBUG) GameServer.addToLog("Combat phase unmanaged, type of combat:"+_type+" T:"+T+" F:"+F);
- }
- break;
- default:
- if(ElinkEmu.CONFIG_DEBUG) GameServer.addToLog("Combat phase unmanaged, type of combat:"+_type+" T:"+T+" F:"+F);
- break;
- }
- }else //If character is viewing the fight
- {
- SocketManager.GAME_SEND_GV_PACKET(perso);
- _spec.remove(perso.get_GUID());
- perso.setSitted(false);
- perso.set_fight(null);
- perso.set_away(false);
- }
- }
|
And this is the code to verify if the player is still in the fight at the end of the fight..
Code :
- public boolean verifyStillInFight()//Return true if at least one player is still in combat
- {
- for(Fighter f : _team0.values())
- {
- if(f.isPerco()) return true;
- if(f.isInvocation()
- || f.isDead()
- || f.getPersonnage() == null
- || f.getMob() != null
- || f._double != null
- || f.hasLeft())
- {
- continue;
- }
- if(f.getPersonnage() != null && f.getPersonnage().get_fight() != null
- && f.getPersonnage().get_fight().get_id() == this.get_id()) //If it is not in this fight
- {
- return true;
- }
- }
- for(Fighter f : _team1.values())
- {
- if(f.isPerco()) return true;
- if(f.isInvocation()
- || f.isDead()
- || f.getPersonnage() == null
- || f.getMob() != null
- || f._double != null
- || f.hasLeft())
- {
- continue;
- }
- if(f.getPersonnage() != null && f.getPersonnage().get_fight() != null
- && f.getPersonnage().get_fight().get_id() == this.get_id()) //If it is not in this fight
- {
- return true;
- }
- }
- return false;
- }
|
|