78
69
        }
69
        }
70
 
70
 
71
        /// <summary>
71
        /// <summary>
72
        /// Ajoute uen entitées sur la cell
72
        /// Ajoute une entitées sur la cell
73
        /// </summary>
73
        /// </summary>
74
        /// <param name="Actor"></param>
74
        /// <param name="Actor"></param>
75
        public void AddActor(IGameActor Actor)
75
        public void AddActor(IGameActor Actor)
...
 
...
 
80
            // on affecte la cell
80
            // on affecte la cell
81
            Actor.CellId = this.Id;
81
            Actor.CellId = this.Id;
82
 
82
 
83
            if (Actor is Character)
83
            if (Actor.ActorType == GameActorTypeEnum.TYPE_CHARACTER)
84
                foreach (var Action in this.myActions)
84
                foreach (var Action in this.myActions)
85
                    Action.Apply(Actor as Character);        
85
                    Action.Apply(Actor as Character);        
86
        }
86
        }
...
 
...
 
116
    /// </summary>    
116
    /// </summary>    
117
    public partial class Map : IWorldEventObserver, IWorldField
117
    public partial class Map : IWorldEventObserver, IWorldField
118
    {
118
    {
 
 
119
        private static Random RANDOM = new Random();
 
 
120
 
119
        private delegate void GenericWorldClientPacket(PacketBase Packet);
121
        private delegate void GenericWorldClientPacket(PacketBase Packet);
120
        private event GenericWorldClientPacket Event_SendToMap;
122
        private event GenericWorldClientPacket Event_SendToMap;
121
 
123
 
...
 
...
 
125
        // trigger cell
127
        // trigger cell
126
        private List<CellAction> myCellActions = new List<CellAction>();
128
        private List<CellAction> myCellActions = new List<CellAction>();
127
 
129
 
 
 
130
        // liste des monstres possibles
 
 
131
        private List<MonsterLevel> myPossibleMonsters = new List<MonsterLevel>();
 
 
132
 
128
        // action de fin de combat
133
        // action de fin de combat
129
        private List<EndFightAction> myEndFightActions = new List<EndFightAction>();
134
        private List<EndFightAction> myEndFightActions = new List<EndFightAction>();
130
 
135
 
...
 
...
 
146
 
151
 
147
        // prochain Id monsters/npcs etc
152
        // prochain Id monsters/npcs etc
148
        private long myNextActorId = -1;
153
        private long myNextActorId = -1;
 
 
154
        public long NextActorId
 
 
155
        {
 
 
156
            get { return myNextActorId--; }
 
 
157
        }
149
 
158
 
150
        // map parente
159
        // map parente
151
        private Map myMap;
160
        private Map myMap;
...
 
...
 
208
                    if (this.myCells.ContainsKey(Action.CellID))
217
                    if (this.myCells.ContainsKey(Action.CellID))
209
                        this.myCells[Action.CellID].AddAction(Action);
218
                        this.myCells[Action.CellID].AddAction(Action);
210
 
219
 
 
 
220
                this.myInitialized = true;
 
 
221
 
211
                foreach (var Npc in this.myMap.Npcs)
222
                foreach (var Npc in this.myMap.Npcs)
212
                    if (this.myCells.ContainsKey(Npc.CellId))
223
                    if (this.myCells.ContainsKey(Npc.CellId))
213
                    {
224
                    {
214
                        Npc.Initialize(this.myNextActorId--);
225
                        Npc.Initialize(this.myNextActorId--);
215
                        this.myCells[Npc.CellId].AddActor(Npc);
226
                        this.SpawnActor(Npc);
216
                        this.myGameActors.Add(Npc.ActorId, Npc);
 
 
217
                    }
227
                    }
218
               
228
 
219
                this.myInitialized = true;
229
                foreach (var MonsterInfo in this.Monsters.Split('|'))
 
 
230
                {
 
 
231
                    if (MonsterInfo != string.Empty)
 
 
232
                    {
 
 
233
                        try
 
 
234
                        {
 
 
235
                            var MonsterData = MonsterInfo.Split(',');
 
 
236
 
 
 
237
                            var MonsterId = int.Parse(MonsterData[0]);
 
 
238
                            var MonsterLevel = int.Parse(MonsterData[1]);
 
 
239
 
 
 
240
                            var Monster = DatabaseEntities.GetMonster(MonsterId);
 
 
241
 
 
 
242
                            if(Monster != null)
 
 
243
                            {
 
 
244
                                var MonsterGrade = Monster.GetLevel(MonsterLevel);
 
 
245
 
 
 
246
                                if (MonsterGrade != null)
 
 
247
                                {
 
 
248
                                    this.myPossibleMonsters.Add(MonsterGrade);
 
 
249
                                }
 
 
250
                            }
 
 
251
                        }
 
 
252
                        catch (Exception ex)
 
 
253
                        {
 
 
254
                        }
 
 
255
                    }
 
 
256
                }
 
 
257
 
 
 
258
                // On spawn 3 groupes
 
 
259
                this.SpawnMonsterGroup(3);
220
            }
260
            }
221
            catch (Exception ex)
261
            catch (Exception ex)
222
            {
262
            {
...
 
...
 
225
        }
265
        }
226
 
266
 
227
        /// <summary>
267
        /// <summary>
 
 
268
        /// Spawn d'un groupe de monster
 
 
269
        /// </summary>
 
 
270
        [MethodImpl(MethodImplOptions.Synchronized)]
 
 
271
        public void SpawnMonsterGroup(int Count)
 
 
272
        {
 
 
273
            if (Count < 1)
 
 
274
                return;
 
 
275
 
 
 
276
            for (int i = 0; i < Count; i++)
 
 
277
            {
 
 
278
                var Group = new MonsterGroup(this.myPossibleMonsters, this.GrouMaxSize, this.NextActorId);
 
 
279
 
 
 
280
                if (Group.Monsters.Count < 1)
 
 
281
                    continue;
 
 
282
 
 
 
283
                this.SpawnActor(Group);
 
 
284
            }
 
 
285
        }
 
 
286
 
 
 
287
        /// <summary>
228
        /// Verifi si l'on peu marcher sur une case
288
        /// Verifi si l'on peu marcher sur une case
229
        /// </summary>
289
        /// </summary>
230
        /// <param name="CellId"></param>
290
        /// <param name="CellId"></param>
...
 
...
 
238
        }
298
        }
239
 
299
 
240
        /// <summary>
300
        /// <summary>
 
 
301
        /// Retourne une cell valide
 
 
302
        /// </summary>
 
 
303
        /// <returns></returns>
 
 
304
        public int GetFreeCell()
 
 
305
        {
 
 
306
            int CellId = -1;
 
 
307
 
 
 
308
            do
 
 
309
            {
 
 
310
                CellId = RANDOM.Next(50, this.myCells.Count - 1);
 
 
311
            }
 
 
312
            while(!this.myCells[CellId].Walkable);
 
 
313
 
 
 
314
            return CellId;
 
 
315
 
 
 
316
            throw new KeyNotFoundException("Impossible de delivrez une cell libre");
 
 
317
        }
 
 
318
 
 
 
319
        /// <summary>
241
        /// Retounr le nombre de cells
320
        /// Retounr le nombre de cells
242
        /// </summary>
321
        /// </summary>
243
        public int CellsCount
322
        public int CellsCount
...
 
...
 
374
                }
453
                }
375
                else
454
                else
376
                {
455
                {
377
                    // TODO this.SpawnToFreeCell(IGameActor);
456
                    Actor.CellId = this.GetFreeCell();
 
 
457
 
 
 
458
                    this.myCells[Actor.CellId].AddActor(Actor);
378
                }
459
                }
379
            }
460
            }
380
        }
461
        }
...
 
...
 
412
            this.SendToMap(new GameActorDestroyMessage(Actor.ActorId));
493
            this.SendToMap(new GameActorDestroyMessage(Actor.ActorId));
413
        }
494
        }
414
 
495
 
 
 
496
        /// <summary>
 
 
497
        /// Enregistre un client au chat
 
 
498
        /// </summary>
 
 
499
        /// <param name="Client"></param>
415
        public void RegisterToChat(WorldClient Client)
500
        public void RegisterToChat(WorldClient Client)
416
        {
501
        {
417
            Client.RegisterChatChannel(this.myChannel);
502
            Client.RegisterChatChannel(this.myChannel);
...
 
...
 
427
            this.myCells[Actor.CellId].DelActor(Actor);
512
            this.myCells[Actor.CellId].DelActor(Actor);
428
 
513
 
429
            this.myCells[NewCell].AddActor(Actor);
514
            this.myCells[NewCell].AddActor(Actor);
 
 
515
 
 
 
516
            // Uniquement si personnage
 
 
517
            if (Actor.ActorType == GameActorTypeEnum.TYPE_CHARACTER)
 
 
518
            {
 
 
519
                // Changement de map ?
 
 
520
                if ((Actor as Character).Map == this.MAP_ID)
 
 
521
                {
 
 
522
                    foreach(var MGroup in this.myGameActors.Values.OfType<MonsterGroup>())
 
 
523
                    {    
 
 
524
                        if (Pathfinder.GoalDistance(this, NewCell, MGroup.CellId) <= MGroup.Aggrodistance)
 
 
525
                        {
 
 
526
                            if ((MGroup.Alignement != -1) || (Actor as Character).Alignment.AlignmentId != MGroup.Alignement)
 
 
527
                            {
 
 
528
                                this.LaunchMonsterFight((Actor as Character).GetClient(), MGroup);
 
 
529
                                break;
 
 
530
                            }
 
 
531
                        }
 
 
532
                    }
 
 
533
                }
 
 
534
            }
430
        }
535
        }
431
 
536
 
432
        /// <summary>
537
        /// <summary>
 
 
538
        /// Lancement d'un combat
 
 
539
        /// </summary>
 
 
540
        /// <param name="Monsters"></param>
 
 
541
        /// <param name="Player"></param>
 
 
542
        [MethodImpl(MethodImplOptions.Synchronized)]
 
 
543
        public void LaunchMonsterFight(WorldClient Player, MonsterGroup Monsters)
 
 
544
        {
 
 
545
            if (Monsters == null | Player == null)
 
 
546
                return;
 
 
547
 
 
 
548
            // Ne peut pas lancer de combat ?
 
 
549
            if (!Player.CanGameAction(GameActionTypeEnum.FIGHT))
 
 
550
                return;
 
 
551
 
 
 
552
            // Lancement du combat
 
 
553
            this.AddFight(new MonsterFight(this, Player, Monsters));
 
 
554
 
 
 
555
            // Despawn des monstres
 
 
556
            this.DestroyActor(Monsters);
 
 
557
        }
 
 
558
 
 
 
559
        /// <summary>
433
        /// Debut d'un combat sur la map ?
560
        /// Debut d'un combat sur la map ?
434
        /// </summary>
561
        /// </summary>
435
        /// <param name="Fight"></param>
562
        /// <param name="Fight"></param>