7 | 8 | ||
---|---|---|---|
106 | private event GenericWorldClientPacket Event_SendToFight; | 106 | private event GenericWorldClientPacket Event_SendToFight; |
107 | 107 | ||
108 | [MethodImpl(MethodImplOptions.Synchronized)] | 108 | [MethodImpl(MethodImplOptions.Synchronized)] |
109 | public abstract void EndFight(FightTeam Loosers); | 109 | public abstract void EndFight(FightTeam Winners, FightTeam Loosers); |
110 | public abstract int GetStartTimer(); | 110 | public abstract int GetStartTimer(); |
111 | public abstract int GetTurnTime(); | 111 | public abstract int GetTurnTime(); |
112 | public abstract void SerializeAs_FlagDisplayInformations(StringBuilder Packet); | ||
112 | 113 | ||
113 | public void SerializeAs_FlagDisplayInformations(StringBuilder Packet) | ||
114 | { | ||
115 | Packet.Append(this.FightId).Append(';'); | ||
116 | Packet.Append((int)this.FightType).Append('|'); | ||
117 | Packet.Append(this.myTeam1.LeaderId).Append(';'); | ||
118 | Packet.Append(this.myTeam1.Leader.MapCell).Append(';'); | ||
119 | Packet.Append(this.myTeam1.Leader.ActorType == GameActorTypeEnum.TYPE_CHARACTER ? '0' : '1').Append(';'); | ||
120 | Packet.Append(this.FightType == FightType.TYPE_AGGRESSION ? (this.myTeam1.Leader as CharacterFighter).Character.Alignment.AlignmentId : -1).Append('|'); | ||
121 | Packet.Append(this.myTeam2.LeaderId).Append(';'); | ||
122 | Packet.Append(this.myTeam2.Leader.MapCell).Append(';'); | ||
123 | Packet.Append(this.myTeam2.Leader.ActorType == GameActorTypeEnum.TYPE_CHARACTER ? '0' : '1').Append(';'); | ||
124 | Packet.Append(this.FightType == FightType.TYPE_AGGRESSION ? (this.myTeam2.Leader as CharacterFighter).Character.Alignment.AlignmentId : -1); | ||
125 | } | ||
126 | 114 | ||
127 | public int FightId | 115 | public int FightId |
128 | { | 116 | { |
... | ... | ||
168 | } | 156 | } |
169 | } | 157 | } |
170 | 158 | ||
159 | public int NextActorId | ||
160 | { | ||
161 | get | ||
162 | { | ||
163 | return this.myNextActorId--; | ||
164 | } | ||
165 | } | ||
166 | |||
171 | // Liste des cells dispo par equipes | 167 | // Liste des cells dispo par equipes |
172 | protected ChatChannel myChatChannel = new ChatChannel(ChatChannelEnum.CHANNEL_GENERAL); | 168 | protected ChatChannel myChatChannel = new ChatChannel(ChatChannelEnum.CHANNEL_GENERAL); |
173 | protected Dictionary<FightTeam, Dictionary<int, FightCell>> myFightCells = new Dictionary<FightTeam, Dictionary<int, FightCell>>(); | 169 | protected Dictionary<FightTeam, Dictionary<int, FightCell>> myFightCells = new Dictionary<FightTeam, Dictionary<int, FightCell>>(); |
... | ... | ||
178 | protected FightTeam myTeam2 = new FightTeam(1); | 174 | protected FightTeam myTeam2 = new FightTeam(1); |
179 | protected int myLoopTimeOut = -1; | 175 | protected int myLoopTimeOut = -1; |
180 | protected int myLoopActionTimeOut; | 176 | protected int myLoopActionTimeOut; |
177 | protected int myNextActorId = -1; | ||
181 | protected GameFightEndResult myResult; | 178 | protected GameFightEndResult myResult; |
182 | protected List<GameAction> myActions = new List<GameAction>(); | 179 | protected List<GameAction> myActions = new List<GameAction>(); |
183 | 180 | ||
... | ... | ||
214 | if (Fight.MAP_FIGHTCELLS.ContainsKey(this.Map.MAP_ID)) | 211 | if (Fight.MAP_FIGHTCELLS.ContainsKey(this.Map.MAP_ID)) |
215 | { | 212 | { |
216 | // Ajout | 213 | // Ajout |
217 | foreach (var Cell in Fight.MAP_FIGHTCELLS[this.Map.MAP_ID][0]) | 214 | lock (Fight.MAP_FIGHTCELLS) |
218 | this.myFightCells[this.myTeam1].Add(Cell, this.myCells[Cell]); | 215 | { |
219 | foreach (var Cell in Fight.MAP_FIGHTCELLS[this.Map.MAP_ID][1]) | 216 | foreach (var Cell in Fight.MAP_FIGHTCELLS[this.Map.MAP_ID][0]) |
220 | this.myFightCells[this.myTeam2].Add(Cell, this.myCells[Cell]); | 217 | this.myFightCells[this.myTeam1].Add(Cell, this.myCells[Cell]); |
218 | foreach (var Cell in Fight.MAP_FIGHTCELLS[this.Map.MAP_ID][1]) | ||
219 | this.myFightCells[this.myTeam2].Add(Cell, this.myCells[Cell]); | ||
220 | } | ||
221 | } | 221 | } |
222 | else | 222 | else |
223 | { | 223 | { |
... | ... | ||
233 | { | 233 | { |
234 | this.myFightCells[this.myTeam2].Add(Algo.CellCharCodeToId(Data[1].Substring(i, 2)), this.myCells[Algo.CellCharCodeToId(Data[1].Substring(i, 2))]); | 234 | this.myFightCells[this.myTeam2].Add(Algo.CellCharCodeToId(Data[1].Substring(i, 2)), this.myCells[Algo.CellCharCodeToId(Data[1].Substring(i, 2))]); |
235 | } | 235 | } |
236 | |||
237 | lock (Fight.MAP_FIGHTCELLS) | ||
238 | { | ||
239 | Fight.MAP_FIGHTCELLS.Add(this.Map.MAP_ID, new Dictionary<int, List<int>>()); | ||
240 | Fight.MAP_FIGHTCELLS[this.Map.MAP_ID].Add(0, this.myFightCells[this.myTeam1].Select(x => x.Key).ToList()); | ||
241 | Fight.MAP_FIGHTCELLS[this.Map.MAP_ID].Add(1, this.myFightCells[this.myTeam2].Select(x => x.Key).ToList()); | ||
242 | } | ||
236 | } | 243 | } |
237 | else | 244 | else |
238 | { | 245 | { |
... | ... | ||
454 | } | 461 | } |
455 | 462 | ||
456 | // Fin du combat | 463 | // Fin du combat |
457 | this.EndFight(this.GetEnnemyTeam(Fighter.Team)); | 464 | this.EndFight(this.GetEnnemyTeam(Fighter.Team), Fighter.Team); |
458 | } | 465 | } |
459 | else | 466 | else |
460 | { | 467 | { |
... | ... | ||
470 | // On envois | 477 | // On envois |
471 | Fighter.Send(new GameLeaveMessage()); | 478 | Fighter.Send(new GameLeaveMessage()); |
472 | } | 479 | } |
473 | break; | 480 | break; |
474 | } | 481 | } |
475 | break; | 482 | break; |
476 | 483 | ||
... | ... | ||
492 | if (this.CurrentFighter == Fighter) | 499 | if (this.CurrentFighter == Fighter) |
493 | this.FightLoopState = FightLoopState.STATE_END_TURN; | 500 | this.FightLoopState = FightLoopState.STATE_END_TURN; |
494 | } | 501 | } |
495 | break; | 502 | break; |
503 | | ||
504 | case Fights.FightType.TYPE_PVM: | ||
505 | // Si combat pas finis | ||
506 | if (Fighter.TryDie(Fighter.ActorId, true) != -3) | ||
507 | { | ||
508 | // Le combattant quitte le combat | ||
509 | Fighter.LeaveFight(); | ||
510 | |||
511 | // On envois | ||
512 | Fighter.Send(new GameLeaveMessage()); | ||
513 | |||
514 | // On passe le tour du joueur | ||
515 | if (this.CurrentFighter == Fighter) | ||
516 | this.FightLoopState = FightLoopState.STATE_END_TURN; | ||
517 | } | ||
518 | break; | ||
496 | } | 519 | } |
497 | break; | 520 | break; |
498 | } | 521 | } |
... | ... | ||
536 | // En attente de lancement | 559 | // En attente de lancement |
537 | this.FightLoopState = Fights.FightLoopState.STATE_WAIT_START; | 560 | this.FightLoopState = Fights.FightLoopState.STATE_WAIT_START; |
538 | 561 | ||
539 | // Lancement du gameLoop | 562 | // Lancement du gameLoop 10 ms d'interval. |
540 | this.StartTimer("GameLoop", this.GameLoop, 10, 10); // Loop infinis | 563 | this.StartTimer("GameLoop", this.GameLoop, 10, 10); |
541 | } | 564 | } |
542 | 565 | ||
543 | /// <summary> | 566 | /// <summary> |
... | ... | ||
558 | this.BeginTurn(); | 581 | this.BeginTurn(); |
559 | break; | 582 | break; |
560 | 583 | ||
561 | case FightLoopState.STATE_WAIT_TURN: // Fin du combat par force | 584 | case FightLoopState.STATE_WAIT_TURN: // Fin du tour par force |
562 | if (this.myLoopTimeOut < Environment.TickCount) | 585 | if (this.myLoopTimeOut < Environment.TickCount) |
563 | { | 586 | { |
564 | if (this.IsActionsFinish() || this.myLoopActionTimeOut < Environment.TickCount) | 587 | if (this.IsActionsFinish() || this.myLoopActionTimeOut < Environment.TickCount) |
... | ... | ||
593 | if (this.IsActionsFinish() ||this.myLoopActionTimeOut < Environment.TickCount) | 616 | if (this.IsActionsFinish() ||this.myLoopActionTimeOut < Environment.TickCount) |
594 | { | 617 | { |
595 | this.EndTurn(); | 618 | this.EndTurn(); |
596 | this.EndFight(this.GetWinners()); | 619 | this.EndFight(this.GetWinners(), this.GetEnnemyTeam(this.GetWinners())); |
597 | } | 620 | } |
598 | break; | 621 | break; |
599 | } | 622 | } |
... | ... | ||
627 | var TacledChance = Pathfinder.TryTacle(Fighter); | 650 | var TacledChance = Pathfinder.TryTacle(Fighter); |
628 | 651 | ||
629 | // Si tacle | 652 | // Si tacle |
630 | if (TacledChance != -1) | 653 | if (TacledChance != -1 && !this.CurrentFighter.States.HasState(FighterStateEnum.STATE_ENRACINER)) |
631 | { | 654 | { |
632 | // XX A été taclé | 655 | // XX A été taclé |
633 | this.SendToFight(new GameActionMessage((int)GameActionTypeEnum.FIGHT_TACLE, Fighter.ActorId)); | 656 | this.SendToFight(new GameActionMessage((int)GameActionTypeEnum.FIGHT_TACLE, Fighter.ActorId)); |
... | ... | ||
758 | { | 781 | { |
759 | var FightCell = this.GetCell(Cell); | 782 | var FightCell = this.GetCell(Cell); |
760 | if(FightCell != null) | 783 | if(FightCell != null) |
761 | if (FightCell.HasGameObject(FightObjectType.OBJECT_FIGHTER)) | 784 | if (FightCell.HasGameObject(FightObjectType.OBJECT_FIGHTER) | FightCell.HasGameObject(FightObjectType.OBJECT_CAWOTTE)) |
762 | Targets[Effect].Add(FightCell.GetFighter()); | 785 | Targets[Effect].AddRange(FightCell.GetObjects<Fighter>()); |
763 | } | 786 | } |
764 | } | 787 | } |
765 | 788 | ||
789 | var ActualChance = 0; | ||
766 | foreach (var Effect in Effects) | 790 | foreach (var Effect in Effects) |
767 | { | 791 | { |
792 | if (Effect.Chance > 0) | ||
793 | { | ||
794 | if(Fight.RANDOM.Next(1, 100) > (Effect.Chance + ActualChance)) | ||
795 | { | ||
796 | ActualChance += Effect.Chance; | ||
797 | continue; | ||
798 | } | ||
799 | ActualChance -= 100; | ||
800 | } | ||
801 | |||
802 | // Actualisation des morts | ||
803 | Targets[Effect].RemoveAll(F => F.Dead); | ||
804 | |||
768 | var CastInfos = new EffectCast(Effect.EffectType, SpellLevel.SPELL_ID, CellId, Effect.Value1, Effect.Value2, Effect.Value3, Effect.Chance, Effect.Duration, Fighter, Targets[Effect]); | 805 | var CastInfos = new EffectCast(Effect.EffectType, SpellLevel.SPELL_ID, CellId, Effect.Value1, Effect.Value2, Effect.Value3, Effect.Chance, Effect.Duration, Fighter, Targets[Effect]); |
769 | 806 | | |
770 | if (EffectBase.TryApplyEffect(CastInfos) == -3) | 807 | if (EffectBase.TryApplyEffect(CastInfos) == -3) |
771 | goto StopAction; | 808 | break; |
772 | } | 809 | } |
773 | } | 810 | } |
774 | 811 | ||
775 | StopAction: | ||
776 | |||
777 | this.SendToFight(new GameActionMessage((int)GameActionTypeEnum.FIGHT_LOSTPA, Fighter.ActorId, Fighter.ActorId + ",-" + SpellLevel.APCost.ToString())); | 812 | this.SendToFight(new GameActionMessage((int)GameActionTypeEnum.FIGHT_LOSTPA, Fighter.ActorId, Fighter.ActorId + ",-" + SpellLevel.APCost.ToString())); |
778 | 813 | ||
779 | if(this.FightLoopState != Fights.FightLoopState.STATE_END_FIGHT) | 814 | if(this.FightLoopState != Fights.FightLoopState.STATE_END_FIGHT) |
... | ... | ||
786 | /// </summary> | 821 | /// </summary> |
787 | /// <param name="Actor"></param> | 822 | /// <param name="Actor"></param> |
788 | /// <param name="NewCell"></param> | 823 | /// <param name="NewCell"></param> |
824 | [MethodImpl(MethodImplOptions.Synchronized)] | ||
789 | public void ActorMoved(MovementPath Path, IGameActor Actor, int NewCell) | 825 | public void ActorMoved(MovementPath Path, IGameActor Actor, int NewCell) |
790 | { | 826 | { |
791 | var Fighter = Actor as Fighter; | 827 | var Fighter = Actor as Fighter; |
... | ... | ||
826 | 862 | ||
827 | // Envois debut du tour | 863 | // Envois debut du tour |
828 | this.SendToFight(new GameTurnStartMessage(this.CurrentFighter.ActorId, this.GetTurnTime())); | 864 | this.SendToFight(new GameTurnStartMessage(this.CurrentFighter.ActorId, this.GetTurnTime())); |
865 | |||
866 | // Monstre passe le tour | ||
867 | if (this.CurrentFighter.ActorType == GameActorTypeEnum.TYPE_MONSTER) | ||
868 | this.FightLoopState = Fights.FightLoopState.STATE_END_TURN; | ||
829 | } | 869 | } |
830 | 870 | ||
831 | /// <summary> | 871 | /// <summary> |
... | ... | ||
907 | /// </summary> | 947 | /// </summary> |
908 | [MethodImpl(MethodImplOptions.Synchronized)] | 948 | [MethodImpl(MethodImplOptions.Synchronized)] |
909 | protected void EndFight() | 949 | protected void EndFight() |
910 | { | 950 | { |
951 | switch (this.FightState) | ||
952 | { | ||
953 | case FightState.STATE_PLACEMENT: | ||
954 | this.Map.SendToMap(new GameFightFlagDestroyMessage(this.FightId)); | ||
955 | break; | ||
956 | |||
957 | case Fights.FightState.STATE_ENDED: | ||
958 | return; | ||
959 | } | ||
960 | |||
911 | this.StopTimer("GameLoop"); | 961 | this.StopTimer("GameLoop"); |
912 | 962 | ||
913 | this.SendToFight(new GameFightEndMessage(this.myResult)); | 963 | this.SendToFight(new GameFightEndMessage(this.myResult)); |
... | ... | ||
929 | this.myWorker = null; | 979 | this.myWorker = null; |
930 | this.myTimers = null; | 980 | this.myTimers = null; |
931 | 981 | ||
932 | this.Map.RemoveFight(this); | 982 | this.Map.RemoveFight(this); |
983 | |||
984 | this.FightState = Fights.FightState.STATE_ENDED; | ||
985 | this.FightLoopState = FightLoopState.STATE_END_FIGHT; | ||
933 | } | 986 | } |
934 | 987 | ||
935 | #region SubMethods | 988 | #region SubMethods |