示例#1
0
        protected override byte[] UseResponse(EntityBase user)
        {
            if (user.Team == Team && user.EntityType == Entity.EntityType.Worker)
            {
                var workerCast = (Worker) user;

                if (workerCast.IsHoldingResources)
                {
                    switch (workerCast.heldResource)
                    {
                        case ResourceTypes.Tree:
                            MyPlayer.Wood += workerCast.resourceCount;
                            break;
                        case ResourceTypes.Glue:
                            MyPlayer.Glue += workerCast.resourceCount;
                            break;
                        case ResourceTypes.Apple:
                            MyPlayer.Apples += workerCast.resourceCount;
                            break;
                        default:
                            break;
                    }

                    MyGameMode.UpdatePlayer(MyPlayer);
                    workerCast.resourceCount = 0;
                }
            }
            return base.UseResponse(user);
        }
示例#2
0
        public virtual void AddEntity(EntityBase entity, ushort id)
        {
            if (entities.ContainsKey(id)) return;

            entity.MyGameMode = this;
            entity.WorldId = id;
            entities.Add(id, entity);

            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);

            writer.Write(id);
            writer.Write((byte) entity.EntityType);
            writer.Write(entity.UpdateData());
            writer.Write(entity.Team);
            SendData(memory.ToArray(), Gamemode.Signature.EntityAdd);
        }
示例#3
0
        protected EntityBase(GameServer _server, Player player)
        {
            HotkeyString = "";
            UseCount = 0;
            Server = _server;
            MyPlayer = player;

            Neutral = false;
            BoundsSize = new Vector2f(10, 10);
            RemoveOnNoHealth = true;

            EntityToUse = null;
            MyGameMode = null;
            rallyPoints = new List<Entity.RallyPoint>();
            Health = 0;
            MaxHealth = 0;
            Energy = 0;
            EnergyRegenRate = 0;
            MaxEnergy = 0;

            Position = new Vector2f();

            spells = new Dictionary<string, SpellData>();
        }
示例#4
0
 protected virtual byte[] UseResponse(EntityBase user)
 {
     return new byte[0];
 }
示例#5
0
        protected virtual byte[] SetEntityToUseResponse(EntityBase toUse)
        {
            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);
            writer.Write((toUse != null));
            EntityToUse = toUse;

            if (toUse != null)
            {
                writer.Write(EntityToUse.WorldId);
            }
            return memory.ToArray();
        }
示例#6
0
        public void Use(EntityBase user)
        {
            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);

            writer.Write(user.WorldId);
            writer.Write(UseResponse(user));

            SendData(memory.ToArray(), Entity.Signature.Use);
        }
示例#7
0
 public void SetEntityToUse(EntityBase toUse)
 {
     byte[] data = SetEntityToUseResponse(toUse);
     SendData(data, Entity.Signature.EntityToUseChange);
 }
示例#8
0
 public void AddEntity(EntityBase ent)
 {
     AddEntity(ent, entityWorldIdToGive);
     entityWorldIdToGive++;
 }
示例#9
0
        public void Remove(EntityBase entity)
        {
            entities.Remove(entity.WorldId);

            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);

            writer.Write(entity.WorldId);
            SendData(memory.ToArray(), Gamemode.Signature.RemoveEntity);
        }
示例#10
0
        protected void SendEntityPosition(EntityBase entity)
        {
            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);

            writer.Write(entity.WorldId);
            writer.Write(entity.Position.X);
            writer.Write(entity.Position.Y);

            SendData(memory.ToArray(), Gamemode.Signature.UpdatePosition);
        }
示例#11
0
 private void moveToUsedEntity(EntityBase toUse)
 {
     if (toUse != null)
     {
         Move(toUse.Position.X, toUse.Position.Y,
              noclipLast:
                  (toUse.EntityType == Entity.EntityType.HomeBuilding ||
                   toUse.EntityType == Entity.EntityType.GlueFactory));
     }
 }
示例#12
0
 protected override byte[] SetEntityToUseResponse(EntityBase toUse)
 {
     State = UnitState.Standard;
     moveToUsedEntity(toUse);
     return base.SetEntityToUseResponse(toUse);
 }
示例#13
0
 protected virtual byte[] onAttack(EntityBase entity)
 {
     if (!RangedUnit) //Happy asshole?
     {
         entity.TakeDamage(StandardAttackDamage, StandardAttackElement, false);
     }
     else
     {
         var rangedBullet = new Projectiles.ProjectileBase(Server, MyPlayer, Position, entity, StandardAttackDamage, StandardAttackElement);
         MyGameMode.AddEntity(rangedBullet);
     }
     return new byte[0];
 }
示例#14
0
        public override void Update(float ms)
        {
            if(EntityToUse != null)
            {
                if (updatedMovePositionTimer.ElapsedMilliseconds >= moveUpdateDelay)
                {
                    updatedMovePositionTimer.Restart();
                    moveToUsedEntity(EntityToUse);
                }
            }
            else
            {
                updatedMovePositionTimer.Reset();
            }
            if (State == UnitState.Agro)
            {
                FloatRect rangeBounds = RangeBounds();
                FloatRect searchBounds = SearchBounds();

                //If the unit has something to attack
                if (EntityToAttack != null)
                {
                    //If the unit is dead, there's nothing to attack
                    if (EntityToAttack.Health <= 0)
                    {
                        EntityToAttack = null;
                        StopAttack();
                    }
                    else
                    {
                        if ( attackTimer.IsRunning == false)
                        {
                            //If the entity to attack is not in range, allow movement
                            if (!rangeBounds.Intersects(EntityToAttack.GetBounds()))
                            {
                                StopAttack();
                                setAllowMove(true);

                                if (!searchBounds.Intersects(EntityToAttack.GetBounds()))
                                {
                                    EntityToAttack = null;
                                }
                                else
                                {
                                    Move(EntityToAttack.Position.X, EntityToAttack.Position.Y,
                                         Entity.RallyPoint.RallyTypes.AttackMove, true, true, "", true);
                                }
                            }
                            else //Otherwize, try to attack and stop ability to move
                            {
                                if (rechargeTimer.ElapsedMilliseconds >= AttackRechargeTime )
                                {
                                    if (rallyPoints.Count > 0)
                                    {
                                        setAllowMove(false);
                                    }
                                    //start the attack
                                    StartAttack();
                                }
                            }
                        }
                        else
                        {
                            if (attackTimer.ElapsedMilliseconds >= AttackDelay)
                            {
                                Attack(EntityToAttack);
                            }
                        }
                    }
                }
                else //Otherwise look for something to attack
                {
                    StopAttack();
                    foreach (EntityBase entity in MyGameMode.WorldEntities.Values)
                    {
                        if (entity.Team == Team) continue;

                        if (!entity.Neutral && entity.Health > 0 && searchBounds.Intersects(entity.GetBounds()))
                        {
                            EntityToAttack = entity;
                            break;
                        }
                    }
                }
            }

            if (EntityToAttack == null || State == UnitState.Standard)
            {
                StopAttack();
                setAllowMove(true);
            }

            if (rallyPoints.Count == 0)
                State = UnitState.Agro;
            //Rallypoint movement

            if (allowMovement && rallyPoints.Count > 0)
            {
                if (rallyPoints[0].RallyType == Entity.RallyPoint.RallyTypes.AttackMove)
                    State = UnitState.Agro;
                else
                    State = UnitState.Standard;

                var destination = new Vector2f(rallyPoints[0].X, rallyPoints[0].Y);

                if ((int) Position.X < (int) destination.X)
                {
                    Position.X += Speed*ms;
                    if ((int) Position.X >= (int) destination.X) _moveXCompleted = true;
                }
                if ((int) Position.Y < (int) destination.Y)
                {
                    Position.Y += Speed*ms;
                    if ((int) Position.Y >= (int) destination.Y) _moveYCompleted = true;
                }
                if ((int) Position.X > destination.X)
                {
                    Position.X -= Speed*ms;
                    if ((int) Position.X <= (int) destination.X) _moveXCompleted = true;
                }
                if ((int) Position.Y > (int) destination.Y)
                {
                    Position.Y -= Speed*ms;
                    if ((int) Position.Y <= (int) destination.Y) _moveYCompleted = true;
                }

                if ((int) Position.X == (int) destination.X) _moveXCompleted = true;
                if ((int) Position.Y == (int) destination.Y) _moveYCompleted = true;

                if (_moveXCompleted && _moveYCompleted)
                {
                    _moveXCompleted = false;
                    _moveYCompleted = false;

                    if (rallyPoints.Count == 1)
                        Position = destination;

                    OnRallyPointCompleted(rallyPoints[0]);
                    rallyPoints.RemoveAt(0);
                    if (rallyPoints.Count == 0)
                    {
                        State = UnitState.Agro;

                        var memory = new MemoryStream();
                        var writer = new BinaryWriter(memory);

                        writer.Write((byte) UnitSignature.RallyCompleted);
                        writer.Write(Position.X);
                        writer.Write(Position.Y);

                        SendData(memory.ToArray(), Entity.Signature.Custom);

                        memory.Close();
                        writer.Close();
                    }
                }
            }
        }
示例#15
0
        public void Attack(EntityBase entity)
        {
            if (entity.Team == Team) return;
            if (attackTimer.ElapsedMilliseconds < AttackDelay) return;

            attackTimer.Reset();
            attackTimer.Stop();

            rechargeTimer.Restart();

            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);

            writer.Write((byte) UnitSignature.Attack);
            writer.Write(entity.WorldId);
            writer.Write(onAttack(entity));

            SendData(memory.ToArray(), Entity.Signature.Custom);

            writer.Close();
            memory.Close();
        }