예제 #1
0
        public void SpawnMobs()
        {
            Log.Debug("Star spawning mobs");
            Random rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                Vector3Net position = new Vector3Net(rand.Next(SpawnOnMapX_Min, SpawnOnMapX_Max), SpawnOnMapY, rand.Next(SpawnOnMapZ_Min, SpawnOnMapZ_Max), Vector3Net.RotationNet.Zero);
                // Vector3Net position = new Vector3Net(20, MapY, 20, Vector3Net.RotationNet.Zero);
                foreach (OccupiedTerritory territory in OccupiedTerritory.OccupiedTerrotpryes)
                {
                    if (!territory.IsContain(position))
                    {
                        Mob.Mob mob = new Mob.Mob(position, rand.Next(1, 4), Mobs.Count + 1);
                        Mobs.Add(Mobs.Count + 1, mob);
                        Log.Debug("Mob: " + Mobs.Count + " | created on | " + mob.Position.X + " : " + mob.Position.Z);
                    }
                    else
                    {
                        position = new Vector3Net(rand.Next(SpawnOnMapX_Min, SpawnOnMapX_Max), SpawnOnMapY, rand.Next(SpawnOnMapZ_Min, SpawnOnMapZ_Max), Vector3Net.RotationNet.Zero);
                        //position = new Vector3Net(20, MapY, 20, Vector3Net.RotationNet.Zero);
                    }
                }
            }
        }
예제 #2
0
        private void MobAttackedByPlayerHandler(OperationRequest operationRequest, SendParameters sendParameters)
        {
            Operations.MobAttackedByPlayer mobAttackedRequest = new Operations.MobAttackedByPlayer(Protocol, operationRequest);

            if (!mobAttackedRequest.IsValid)
            {
                SendOperationResponse(mobAttackedRequest.GetResponse(ErrorCode.InvaildParameters), sendParameters);
                return;
            }

            //if (World.Instance.Mobs.ContainsKey(mobAttackedRequest.MobID))
            //{

            //}
            Log.Debug("Mob#" + mobAttackedRequest.MobID + " attaked by player#" + PlayerID + " (-" + mobAttackedRequest.Damage + ")");
            Mob.Mob mob = World.Instance.Mobs[mobAttackedRequest.MobID];
            mob.Coins -= mobAttackedRequest.Damage;

            //Log.Debug("Mob coins:" + mob.Coins + " | " + mob.StartCoins + " | isDead? " + mob.IsDead);

            if (mob.Dead)
            {
                MobDiedEvent(mob.MobID);
                OperationResponse response = new OperationResponse((byte)OperationCode.MobDefeatedByPlayer);
                response.Parameters = new Dictionary <byte, object> {
                    { (byte)ParameterCode.MobID, mob.MobID }, { (byte)ParameterCode.Coins, mob.StartCoins }
                };
                SendOperationResponse(response, sendParameters);
            }
            else
            {
                EventData eventData = new EventData((byte)EventCode.MobAttackedByPlayer);
                eventData.Parameters = new Dictionary <byte, object> {
                    { (byte)ParameterCode.MobID, mobAttackedRequest.MobID },
                    { (byte)ParameterCode.Damage, mobAttackedRequest.Damage },
                    { (byte)ParameterCode.PlayerID, PlayerID }
                };
                eventData.SendTo(World.Instance.GetClientsList(), sendParameters);
            }
        }