Пример #1
0
        public override void Swing(Damageable target)
        {
            if (fireCooldown < 0)
            {
                hitting = true;

                if (target is Unit)
                {
                    AggroEvent e = new AggroEvent(this, target, true);
                    ((Unit)target).OnAggroRecieved(e);
                    this.OnAggro(e);
                }

                SoundManager.GetInstance().PlaySFX(SoundManager.GetInstance().lanceSounds);

                DamageEvent dmgEvent = new DamageEvent(new MeleeSwing(PathfindingTest.Combat.DamageEvent.DamageType.Melee, baseDamage), target, this);
                target.OnDamage(dmgEvent);
                this.fireCooldown = this.rateOfFire;

                // We already know that this unit is local
                if (Game1.GetInstance().IsMultiplayerGame())
                {
                    Synchronizer.GetInstance().QueueDamageEvent(dmgEvent);
                }
            }
        }
Пример #2
0
        public Projectile(Unit parent, Unit target, DamageEvent.DamageType type, float movementSpeed, int maxRange, int baseDamage)
        {
            this.parent = (Bowman)parent;
            this.x = parent.x;
            this.y = parent.y;
            this.startX = this.x;
            this.startY = this.y;

            this.target = target;
            this.type = type;
            this.movementSpeed = movementSpeed;
            this.maxRange = maxRange;
            this.baseDamage = baseDamage;

            this.waypoint = Util.GetPointOnCircle(parent.GetLocation(), maxRange,
                Util.GetHypoteneuseAngleDegrees(parent.GetLocation(), target.GetLocation()));

            int targetX = (int)target.x;
            int targetY = (int)target.y;

            SetMoveToTarget(targetX, targetY);

            if (Game1.GetInstance().IsMultiplayerGame())
            {
                Boolean isLocal = this.parent.player == Game1.CURRENT_PLAYER;
                this.multiplayerData = new ProjectileMultiplayerData(this, isLocal);
                if (isLocal)
                {
                    this.multiplayerData.RequestServerID();
                }
            }
        }
Пример #3
0
 public Boolean AlreadyInQueue(DamageEvent e)
 {
     try
     {
         for (int i = 0; i < this.eventList.Count(); i++)
         {
             DamageEvent currentEvent = this.eventList.ElementAt(i);
             if (currentEvent == e) return true;
         }
         return false;
     }
     catch (Exception ex) { return false; }
 }
Пример #4
0
        /// <summary>
        /// Attempt to swing the weapon!
        /// </summary>
        public override void Swing()
        {
            AggroEvent e = new AggroEvent(this, unitToStalk, true);
            unitToStalk.OnAggroRecieved(e);
            this.OnAggro(e);
            DamageEvent dmgEvent = new DamageEvent(new MeleeSwing(PathfindingTest.Combat.DamageEvent.DamageType.Melee, baseDamage), unitToStalk, this);
            unitToStalk.OnDamage(dmgEvent);
            this.fireCooldown = this.rateOfFire;

            // We already know that this unit is local
            if (Game1.GetInstance().IsMultiplayerGame())
            {
                Synchronizer.GetInstance().QueueDamageEvent(dmgEvent);
            }
        }
Пример #5
0
        public Projectile(CombatUnit parent, Unit target, DamageEvent.DamageType type, float movementSpeed, int maxRange, int baseDamage)
        {
            this.parent = parent;
            this.x = parent.x;
            this.y = parent.y;
            this.startX = this.x;
            this.startY = this.y;

            this.target = target;
            this.type = type;
            this.movementSpeed = movementSpeed;
            this.maxRange = maxRange;
            this.baseDamage = baseDamage;

            this.waypoint = Util.GetPointOnCircle(parent.GetLocation(), maxRange,
                Util.GetHypoteneuseAngleDegrees(parent.GetLocation(), target.GetLocation()));

            int targetX = (int)target.x;
            int targetY = (int)target.y;

            SetMoveToTarget(targetX, targetY);
        }
Пример #6
0
        public Projectile(Unit parent, Damageable target, DamageEvent.DamageType type, float movementSpeed, int maxRange, int baseDamage)
        {
            this.parent = (Bowman)parent;
            this.x = parent.x + (23 * (float)Math.Cos(parent.rotation));
            this.y = parent.y + (7 * (float)Math.Sin(parent.rotation));
            this.startX = this.x;
            this.startY = this.y;

            this.target = target;
            this.type = type;
            this.movementSpeed = movementSpeed;
            this.maxRange = maxRange;
            this.baseDamage = baseDamage;

            if (target is Unit)
            {
                int targetX = (int)((Unit)target).x;
                int targetY = (int)((Unit)target).y;
                this.waypoint = new Point(targetX, targetY);
                SetMoveToTarget(targetX, targetY);
            }
            else
            {
                int targetX = (int)((Building)target).x;
                int targetY = (int)((Building)target).y;
                this.waypoint = new Point(targetX, targetY);
                SetMoveToTarget(targetX, targetY);
            }

            if (Game1.GetInstance().IsMultiplayerGame())
            {
                Boolean isLocal = this.parent.player == Game1.CURRENT_PLAYER;
                this.multiplayerData = new ProjectileMultiplayerData(this, isLocal);
                if (isLocal)
                {
                    this.multiplayerData.RequestServerID();
                }
            }
        }
Пример #7
0
 public void OnDamage(DamageEvent e)
 {
     this.currentHealth -= e.damageDone;
     if (this.currentHealth <= 0) this.Dispose();
 }
Пример #8
0
 public void OnDamage(DamageEvent e)
 {
     if (unitToStalk == null)
     {
         unitToStalk = e.source;
     }
     this.currentHealth -= e.damageDone;
     if (this.currentHealth <= 0)
     {
         this.Dispose();
     }
 }
Пример #9
0
 public void Hit()
 {
     Console.WriteLine("Target has been hit!");
     DamageEvent e = new DamageEvent(this, target, parent);
     target.OnDamage(e);
     if (Game1.GetInstance().IsMultiplayerGame())
     {
         Synchronizer.GetInstance().QueueDamageEvent(e);
     }
     else
     {
         this.Dispose();
     }
     return;
 }
Пример #10
0
 public void OnDamage(DamageEvent e)
 {
     this.currentHealth -= e.damageDone;
     if (this.currentHealth <= 0 && !this.isDestroyed)
     {
         this.Dispose();
     }
 }
Пример #11
0
 public void QueueDamageEvent(DamageEvent e)
 {
     this.eventList.AddLast(e);
 }
Пример #12
0
 /// <summary>
 /// Identify the source of the DamageSource.
 /// </summary>
 /// <param name="type">The source to identify.</param>
 /// <returns>The identified source.</returns>
 private int EncodeMeleeSwing(DamageEvent.DamageType type)
 {
     if( type == DamageEvent.DamageType.Fast ){
         return UnitHeaders.DAMAGE_TYPE_FAST;
     }
     else if (type == DamageEvent.DamageType.HeavyMelee)
     {
         return UnitHeaders.DAMAGE_TYPE_HEAVY_MELEE;
     }
     else if (type == DamageEvent.DamageType.Melee)
     {
         return UnitHeaders.DAMAGE_TYPE_MELEE;
     }
     else if (type == DamageEvent.DamageType.Ranged)
     {
         return UnitHeaders.DAMAGE_TYPE_RANGED;
     }
     return -1;
 }
Пример #13
0
 public MeleeSwing(DamageEvent.DamageType type, int baseDamage)
 {
     this.type = type;
     this.baseDamage = baseDamage;
 }
Пример #14
0
 public void QueueDamageEvent(DamageEvent e)
 {
     if (!this.AlreadyInQueue(e)) this.eventList.AddLast(e);
 }
Пример #15
0
        private void CheckCollision()
        {
            // Collision events are handled by the owning player, including arrow remove events
            if (Game1.GetInstance().IsMultiplayerGame() &&
                ( this.parent.player != Game1.CURRENT_PLAYER )) return;

            Point collisionLocation = Util.GetPointOnCircle(this.GetLocation(), this.texture.Height / 2,
                        (float)(Util.GetHypoteneuseAngleDegrees(this.GetLocation(), this.waypoint)));
            foreach (Player player in Game1.GetInstance().players)
            {
                foreach (Unit unit in player.units)
                {
                    // Projectiles don't hit friendly targets
                    if (unit.player.alliance.members.Contains(this.parent.player)) continue;
                    //if (this.waypoints.Count != 0)
                    //{
                    // Check if the units are close enough
                    if (unit.DefineRectangle().Contains(
                        // Front of projectile!
                        collisionLocation))
                    {
                        DamageEvent e = new DamageEvent(this, unit, parent);
                        unit.OnDamage(e);
                        if( Game1.GetInstance().IsMultiplayerGame() ) Synchronizer.GetInstance().QueueDamageEvent(e);
                        // Console.Out.WriteLine("Projectile had an impact!");
                        else this.Dispose();
                        return;
                    }
                    //}
                }
            }
        }
Пример #16
0
        public void DataReceived(Packet p)
        {
            switch (p.GetHeader())
            {
                case UnitHeaders.GAME_UNIT_LOCATION:
                    {
                        int serverID = PacketUtil.DecodePacketInt(p, 0);
                        int targetX = PacketUtil.DecodePacketInt(p, 4);
                        int targetY = PacketUtil.DecodePacketInt(p, 8);
                        int currentX = PacketUtil.DecodePacketInt(p, 12);
                        int currentY = PacketUtil.DecodePacketInt(p, 16);

                        MultiplayerData data;
                        int count = 0;
                        do {
                            data = MultiplayerDataManager.GetInstance().GetDataByServerID(serverID);
                            count++;
                            if (count > 15)
                            {
                                Console.Out.WriteLine("Unable to fetch data, requesting..");
                                Packet packet = new Packet(UnitHeaders.GAME_REQUEST_UNIT_DATA);
                                packet.AddInt(Game1.CURRENT_PLAYER.multiplayerID);
                                packet.AddInt(serverID);
                                GameServerConnectionManager.GetInstance().SendPacket(packet);

                                return;
                            }
                        }
                        while (data == null);

                        Unit unit = ((UnitMultiplayerData)data).unit;

                        if (unit.waypoints.Count == 0 || unit.waypoints.Last.Value.X != targetX ||
                            unit.waypoints.Last.Value.Y != targetY)
                        {
                            Point target = new Point(targetX, targetY);
                            unit.multiplayerData.moveTarget = target;
                            unit.multiplayerData.receivedPathRequest = true;
                            unit.MoveToQueue(target);
                        }

                        if (Math.Abs(unit.x - currentX) > 20 || Math.Abs(unit.y - currentY) > 20)
                        {
                            // Uhoh .. we're too far apart :(
                            unit.x = currentX;
                            unit.y = currentY;
                        }

                        break;
                    }
                case UnitHeaders.GAME_NEW_UNIT:
                    {

                        int playerID = PacketUtil.DecodePacketInt(p, 0);
                        int serverID = PacketUtil.DecodePacketInt(p, 4);
                        int type = PacketUtil.DecodePacketInt(p, 8);

                        CreateUnit(playerID, serverID, type);

                        break;
                    }
                case UnitHeaders.GAME_REQUEST_UNIT_DATA:
                    {
                        int targetUserID = PacketUtil.DecodePacketInt(p, 0);
                        int serverID = PacketUtil.DecodePacketInt(p, 4);
                        Console.Out.WriteLine("Received unit data request by " + targetUserID + ": " + serverID);
                        // Someone wants to know data
                        MultiplayerData data = MultiplayerDataManager.GetInstance().GetDataByServerID(serverID);

                        if (data != null && data.isLocal)
                        {
                            Packet response = new Packet(UnitHeaders.GAME_SEND_UNIT_DATA);
                            response.AddInt(targetUserID);
                            response.AddInt(Game1.CURRENT_PLAYER.multiplayerID);
                            response.AddInt(serverID);
                            response.AddInt(data.GetObjectType());
                            GameServerConnectionManager.GetInstance().SendPacket(response);

                            // Queue it for a location update, since someone missed the previous one.
                            if (data is UnitMultiplayerData)
                                Synchronizer.GetInstance().QueueUnit(((UnitMultiplayerData)data).unit);
                            //else if( data is BuildingMultiplayerData )
                                //Synchronizer.GetInstance().QueueBuilding((BuildingMultiplayerData)data));
                        }
                        break;
                    }
                case UnitHeaders.GAME_SEND_UNIT_DATA:
                    {
                        // We received missing data!
                        int playerID = PacketUtil.DecodePacketInt(p, 4);
                        int serverID = PacketUtil.DecodePacketInt(p, 8);
                        int type = PacketUtil.DecodePacketInt(p, 12);

                        CreateUnit(playerID, serverID, type);
                        break;
                    }
                case UnitHeaders.GAME_UNIT_MELEE_DAMAGE:
                    {
                        int damageSource = PacketUtil.DecodePacketInt(p, 0);
                        int fromServerID = PacketUtil.DecodePacketInt(p, 4);
                        int toServerID = PacketUtil.DecodePacketInt(p, 8);
                        Unit fromUnit = ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(fromServerID)).unit;
                        Unit targetUnit = ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(toServerID)).unit;

                        DamageEvent e = new DamageEvent(DecodeSource(damageSource, fromServerID), targetUnit, fromUnit);

                        targetUnit.OnDamage(e);
                        break;
                    }
                case UnitHeaders.GAME_UNIT_RANGED_SHOT:
                    {
                        int arrowServerID = PacketUtil.DecodePacketInt(p, 4);
                        int sourceServerID = PacketUtil.DecodePacketInt(p, 4);
                        int targetServerID = PacketUtil.DecodePacketInt(p, 8);
                        Unit sourceUnit =
                            ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(sourceServerID)).unit;
                        Arrow arrow = new Arrow(sourceUnit,
                            ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(targetServerID)).unit);
                        arrow.multiplayerData.serverID = arrowServerID;
                        ((Bowman)sourceUnit).projectiles.AddLast(arrow);

                        break;
                    }
                case UnitHeaders.GAME_UNIT_RANGED_DAMAGE:
                    {
                        int projectileID = PacketUtil.DecodePacketInt(p, 0);
                        int sourceID = PacketUtil.DecodePacketInt(p, 4);
                        int targetID = PacketUtil.DecodePacketInt(p, 8);
                        Unit sourceUnit = ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(sourceID)).unit;
                        Unit targetUnit = ((UnitMultiplayerData)MultiplayerDataManager.GetInstance().GetDataByServerID(targetID)).unit;
                        Projectile projectile =
                            ((ProjectileMultiplayerData) MultiplayerDataManager.GetInstance().GetDataByServerID(projectileID)).projectile;

                        DamageEvent e = new DamageEvent(projectile, targetUnit, sourceUnit);
                        targetUnit.OnDamage(e);

                        projectile.Dispose();
                        break;
                    }
            }
        }