public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];

            switch (type)
            {
                case (ComponentMessageType.RequestActionList):
                    SendFullListing(client);
                    break;

                case (ComponentMessageType.GetActionChecksum):
                    Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, client,
                                                              ComponentMessageType.GetActionChecksum,
                                                              (uint) (Actions.Sum(x => x.uid)*Actions.Count));
                    break;

                case (ComponentMessageType.DoAction):
                    DoAction(message);
                    break;

                default:
                    base.HandleNetworkMessage(message, client);
                    break;
            }
        }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
 {
     /*var x = (float)message.MessageParameters[0];
     var y = (float)message.MessageParameters[1];
     if((bool)message.MessageParameters[2]) //"forced" parameter -- if true forces position update
     PlainTranslate((float)x, (float)y);*/
 }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     // TODO change these things to flow to the server via a system instead of via this component
     if (message.ComponentFamily == ComponentFamily.Equipment)
     {
         var type = (ComponentMessageType) message.MessageParameters[0];
         switch (type) //Why does this send messages to itself THIS IS DUMB AND WILL BREAK THINGS. BZZZ
         {
             case ComponentMessageType.EquipItem:
                 RaiseEquipItem(Owner.EntityManager.GetEntity((int)message.MessageParameters[1]));
                 break;
             case ComponentMessageType.EquipItemInHand:
                 RaiseEquipItemInHand();
                 break;
             case ComponentMessageType.UnEquipItemToFloor:
                 RaiseUnEquipItemToFloor(Owner.EntityManager.GetEntity((int)message.MessageParameters[1]));
                 break;
             case ComponentMessageType.UnEquipItemToHand:
                 RaiseUnEquipItemToHand(Owner.EntityManager.GetEntity((int)message.MessageParameters[1]));
                 break;
             case ComponentMessageType.UnEquipItemToSpecifiedHand:
                 RaiseUnEquipItemToSpecifiedHand(Owner.EntityManager.GetEntity((int)message.MessageParameters[1]), (InventoryLocation)message.MessageParameters[2]);
                 break;
         }
     }
 }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
 {
     switch ((ComponentMessageType) message.MessageParameters[0])
     {
         case ComponentMessageType.GetSVars:
             HandleGetSVars(message);
             break;
     }
 }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
        {
            var keyFunction = (BoundKeyFunctions) message.MessageParameters[0];
            var keyState = (BoundKeyState) message.MessageParameters[1];

            Owner.SendMessage(this, ComponentMessageType.BoundKeyChange, keyFunction, keyState);
            Owner.RaiseEvent(new BoundKeyChangeEventArgs{KeyFunction = keyFunction, KeyState = keyState, Actor = Owner});
            var boolState = keyState == BoundKeyState.Down;

            SetKeyState(keyFunction, boolState);
        }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            base.HandleNetworkMessage(message, sender);

            switch ((ComponentMessageType) message.MessageParameters[0])
            {
                case ComponentMessageType.SetBaseName:
                    //basename = (string) message.MessageParameters[1];
                    break;
            }
        }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
 {
     base.HandleNetworkMessage(message, sender);
     var type = (ComponentMessageType) message.MessageParameters[0];
     switch (type)
     {
         case ComponentMessageType.SetLightMode:
             SetMode((LightModeClass) message.MessageParameters[1]);
             break;
     }
 }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     switch ((ComponentMessageType) message.MessageParameters[0])
     {
         case ComponentMessageType.Bumped:
             ///TODO check who bumped us, how far away they are, etc.
             Entity bumper = Owner.EntityManager.GetEntity((int) message.MessageParameters[1]);
             if (bumper != null)
                 Owner.SendMessage(this, ComponentMessageType.Bumped, bumper);
             break;
     }
 }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];

            switch (type)
            {
                // TODO refactor me -- health status data should flow entirely via states -- maybe this is true, but right now its using both...
                case (ComponentMessageType.HealthStatus):
                    HandleHealthUpdate(message);
                    break;
            }
        }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     switch ((ComponentMessageType) message.MessageParameters[0])
     {
         //TODO route these through the InventorySystem
         case ComponentMessageType.InventoryAdd:
             Entity entAdd = Owner.EntityManager.GetEntity((int) message.MessageParameters[1]);
             if (entAdd != null)
                 AddToInventory(entAdd);
                 //AddToInventory(entAdd);
             break;
     }
 }
        public void HandleHealthUpdate(IncomingEntityComponentMessage msg)
        {
            var part = (BodyPart) msg.MessageParameters[1];
            var dmgCount = (int) msg.MessageParameters[2];
            var maxHP = (int) msg.MessageParameters[3];

            if (DamageZones.Exists(x => x.Location == part))
            {
                DamageLocation existingZone = DamageZones.First(x => x.Location == part);
                existingZone.MaxHealth = maxHP;

                for (int i = 0; i < dmgCount; i++)
                {
                    var type = (DamageType) msg.MessageParameters[4 + (i*2)];
                    //Retrieve data from message in pairs starting at 4
                    var amount = (int) msg.MessageParameters[5 + (i*2)];

                    if (existingZone.DamageIndex.ContainsKey(type))
                        existingZone.DamageIndex[type] = amount;
                    else
                        existingZone.DamageIndex.Add(type, amount);
                }

                existingZone.UpdateTotalHealth();
            }
            else
            {
                var newZone = new DamageLocation(part, maxHP, maxHP);
                DamageZones.Add(newZone);

                for (int i = 0; i < dmgCount; i++)
                {
                    var type = (DamageType) msg.MessageParameters[4 + (i*2)];
                    //Retrieve data from message in pairs starting at 4
                    var amount = (int) msg.MessageParameters[5 + (i*2)];

                    if (newZone.DamageIndex.ContainsKey(type))
                        newZone.DamageIndex[type] = amount;
                    else
                        newZone.DamageIndex.Add(type, amount);
                }

                newZone.UpdateTotalHealth();
            }

            MaxHealth = GetMaxHealth();
            Health = GetHealth();
            if (Health <= 0) Die(); //Need better logic here.

            IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.TargetingUi);
        }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];
            switch (type)
            {
                case (ComponentMessageType.GetArmorValues): //Add message for sending complete listing.
                    //Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, client, ComponentMessageType.ReturnArmorValues, (int)((DamageType)message.MessageParameters[1]), GetArmorValue((DamageType)message.MessageParameters[1]));
                    break;

                default:
                    base.HandleNetworkMessage(message, client);
                    break;
            }
        }
 /// <summary>
 /// NetMessage handler
 /// </summary>
 /// <param name="message"></param>
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     if (message.ComponentFamily == ComponentFamily.Click)
     {
         var type = (ComponentMessageType) message.MessageParameters[0];
         var uid = (int) message.MessageParameters[1];
         var mouseClickType = MouseClickType.None;
         if(type == ComponentMessageType.LeftClick || type == ComponentMessageType.RightClick || type == ComponentMessageType.ClickedInHand)
         {
             Owner.SendMessage(this, type, uid);
             mouseClickType = MouseClickType.ConvertComponentMessageTypeToClickType(type);
         }
         Owner.RaiseEvent(new ClickedOnEntityEventArgs { Clicked = Owner.Uid, Clicker = uid, MouseButton = mouseClickType });
     }
 }
        public void HandleGetSVars(IncomingEntityComponentMessage message)
        {
            //If nothing's listening, then why bother with this shit?
            if (GetSVarsCallback == null)
                return;
            var count = (int) message.MessageParameters[1];
            var svars = new List<MarshalComponentParameter>();
            for (int i = 2; i < count + 2; i++)
            {
                svars.Add(MarshalComponentParameter.Deserialize((byte[]) message.MessageParameters[i]));
            }

            GetSVarsCallback(this, new GetSVarsEventArgs(svars));
            GetSVarsCallback = null;
        }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];

            switch (type)
            {
                case (ComponentMessageType.ReturnArmorValues):
                    if (!armorStats.Keys.Contains((DamageType) message.MessageParameters[1]))
                        armorStats.Add((DamageType) message.MessageParameters[1], (int) message.MessageParameters[2]);
                    else
                        armorStats[(DamageType) message.MessageParameters[1]] = (int) message.MessageParameters[2];
                    break;

                default:
                    base.HandleNetworkMessage(message, sender);
                    break;
            }
        }
        /// <summary>
        /// Handles position messages. that should be it.
        /// </summary>
        /// <param name="message"></param>
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
        {
            bool shouldMove = true;
            if (Owner.HasComponent(ComponentFamily.StatusEffects))
            {
                var statComp = (StatusEffectComp) Owner.GetComponent(ComponentFamily.StatusEffects);
                if (statComp.HasFamily(StatusEffectFamily.Root) || statComp.HasFamily(StatusEffectFamily.Stun))
                    shouldMove = false;
            }

            if (shouldMove)
            {
                var velComp = Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
                var transform = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);

                velComp.Velocity = new Vector2f((float)message.MessageParameters[2], (float)message.MessageParameters[3]);
                transform.Position = new Vector2f((float)message.MessageParameters[0], (float)message.MessageParameters[1]);
            }
        }
 private void DoAction(IncomingEntityComponentMessage message)
 {
     PlayerAction toDo =
         Actions.FirstOrDefault(
             x =>
             x.uid == (uint) message.MessageParameters[1] &&
             (PlayerActionTargetType) message.MessageParameters[2] == x.targetType);
     if (toDo != null)
     {
         double cdLeft = toDo.cooldownExpires.Subtract(DateTime.Now).TotalSeconds;
         if (cdLeft > 0) //Tried to use something while on cooldown. Shouldnt happen but might.
         {
             return; //Send fail later?
         }
         else
         {
             if (toDo.targetType == PlayerActionTargetType.Any || toDo.targetType == PlayerActionTargetType.Other ||
                 toDo.targetType == PlayerActionTargetType.None)
                 //Check validity of targets later. Only clientside atm.
             {
                 Entity ent = Owner.EntityManager.GetEntity((int) message.MessageParameters[3]);
                 //ent id clienside uint but server int. Why?!
                 if (ent != null)
                 {
                     toDo.OnUse(ent);
                 }
                 else
                     return; //Invalid target. Send fail later?
             }
             else if (toDo.targetType == PlayerActionTargetType.Point)
             {
                 var trg = new PointF((float) message.MessageParameters[3], (float) message.MessageParameters[4]);
                 toDo.OnUse(trg);
             }
         }
     }
     else
     {
         //They asked us to do something we don't have.
         //Send full listing or error ?! TODO.
     }
 }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];
            int entityUid;
            InventoryLocation usedHand;
            Entity item;

            switch (type)
            {
                case (ComponentMessageType.EntityChanged):
                    //This is not sent atm. Commented out serverside for later use.
                    entityUid = (int) message.MessageParameters[1];
                    usedHand = (InventoryLocation)message.MessageParameters[2];
                    item = Owner.EntityManager.GetEntity(entityUid);
                    if (HandSlots.Keys.Contains(usedHand))
                        HandSlots[usedHand] = item;
                    else
                        HandSlots.Add(usedHand, item);
                    break;
                case (ComponentMessageType.HandsDroppedItem):
                    //entityUid = (int)message.MessageParameters[1];
                    usedHand = (InventoryLocation)message.MessageParameters[2];
                    //item = EntityManager.Singleton.GetEntity(entityUid);
                    //item.SendMessage(this, ComponentMessageType.Dropped, null);
                    HandSlots.Remove(usedHand);
                    break;
                case (ComponentMessageType.HandsPickedUpItem):
                    entityUid = (int) message.MessageParameters[1];
                    usedHand = (InventoryLocation)message.MessageParameters[2];
                    item = Owner.EntityManager.GetEntity(entityUid);
                    //item.SendMessage(this, ComponentMessageType.PickedUp, null, usedHand);
                    HandSlots.Add(usedHand, item);
                    break;
                case ComponentMessageType.ActiveHandChanged:
                    SwitchHandTo((InventoryLocation)message.MessageParameters[1]);
                    break;
            }

            IoCManager.Resolve<IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
        }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            var type = (ComponentMessageType) message.MessageParameters[0];

            switch (type)
            {
                case (ComponentMessageType.AddAction):
                    var typeName = (string) message.MessageParameters[1];
                    var uid = (uint) message.MessageParameters[2];
                    AddAction(typeName, uid);
                    break;

                case (ComponentMessageType.RemoveAction):
                    var uid2 = (uint) message.MessageParameters[1];
                    RemoveAction(uid2);
                    break;

                case (ComponentMessageType.RequestActionList):
                    UnpackFullListing(message);
                    break;

                case (ComponentMessageType.GetActionChecksum):
                    CheckFullUpdate((uint) message.MessageParameters[1]);
                    break;

                case (ComponentMessageType.CooldownAction):
                    var uidCd = (uint) message.MessageParameters[1];
                    var secCd = (uint) message.MessageParameters[2];
                    SetCooldown(uidCd, secCd);
                    break;

                default:
                    base.HandleNetworkMessage(message, sender);
                    break;
            }
        }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     if (message.ComponentFamily == ComponentFamily.Hands)
     {
         var type = (ComponentMessageType) message.MessageParameters[0];
         var replies = new List<ComponentReplyMessage>();
         switch (type)
         {
             case ComponentMessageType.ActiveHandChanged:
                 var hand = (InventoryLocation)message.MessageParameters[1];
                 SwitchHandsTo(hand);
                 break;
             case ComponentMessageType.DropEntityInHand:
                 Drop(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
                 break;
             case ComponentMessageType.DropItemInHand:
                 var dhand = (InventoryLocation)message.MessageParameters[1];
                 Drop(dhand);
                 break;
         }
     }
 }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
 {
 }
        private void UnpackFullListing(IncomingEntityComponentMessage message)
        {
            Reset();

            var numPacks = (uint) message.MessageParameters[1];

            for (int i = 0; i < numPacks; i++)
            {
                var uid = (uint) message.MessageParameters[2 + (i*2)];
                var typeName = (string) message.MessageParameters[3 + (i*2)];
                AddAction(typeName, uid);
            }
        }
 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
 {
     switch ((ComponentMessageType) message.MessageParameters[0])
     {
         case ComponentMessageType.SetVisible:
             visible = (bool) message.MessageParameters[1];
             break;
         case ComponentMessageType.SetSpriteByKey:
             SetSpriteByKey((string) message.MessageParameters[1]);
             break;
     }
 }