public static Action <Entity> EntityAction(int actionID)
    {
        switch (actionID)
        {
        case 0:
            return(new Action <Entity>((target) =>
            {
                if (Vector3.Distance(EntityHandler.GetEntity <NPC>(0).transform.position, target.transform.position) <= 3f)
                {
                    ActionPacket packet = (ActionPacket)actionHandler.GetComponent(typeof(OpenChat));

                    if ((target as Player).questStateLib[0] <= 0)
                    {
                        GetPacket(typeof(OpenChat)).Invoke(target.id, 0);
                    }
                    else if ((target as Player).questStateLib[0] == 1)
                    {
                        GetPacket(typeof(OpenChat)).Invoke(target.id, 1);
                    }
                }
                else
                {
                    EntityHandler.DestroyEntity <Player>(target);
                }
            }));

        default:
            return(null);
        }
    }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     while (actions.Count > 0)
     {
         ActionPacket act_p = actions.Dequeue();
         if (act_p.actionName == "move")
         {
             move(act_p.args);
         }
     }
 }
예제 #3
0
 public bool SendPacket(ActionPacket packet)
 {
     using (var client = new NamedPipeClientStream("USBHelperLauncher"))
     {
         client.Connect();
         DataStream ds    = new DataStream(client);
         XDocument  doc   = packet.Serialize();
         byte[]     bytes = Encoding.UTF8.GetBytes(doc.ToString());
         ds.WriteByteArray(bytes, CompressionLevel.Fastest);
         client.Flush();
         byte result = (byte)client.ReadByte();
         client.Close();
         return(BitConverter.ToBoolean(new byte[] { result }, 0));
     }
 }
예제 #4
0
        private void ActionProcess(Packet p_Packet, Player p_Player)
        {
            ActionPacket l_Packet = (ActionPacket)p_Packet;

            foreach (Entity l_Entity in p_Player.Selection)
            {
                l_Entity.Action = l_Packet.Action;
                if (l_Packet.Id == 0)
                {
                    l_Entity.Cible = new WorldPosition(new Vector3D(l_Packet.Pos_X, 0, l_Packet.Pos_Y));
                }
                else
                {
                    l_Entity.Cible = Game.Instance.EntityManager.GetEntity(l_Packet.Id);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Takes in action from client, updates the rest of the clients
 /// </summary>
 /// <param name="packet"></param>
 public static void ReceiveActionUpdate(ActionPacket packet)
 {
     Console.WriteLine(packet.Action);
     GameStateController.AcceptAction(packet);
     //Checks if anyone has won the game
     if (GameStateController.GameOver)
     {
         DeclareWinner();
     }
     else
     {
         SendMonsterPackets(sendDice:
                            packet.Action == Networking.Actions.Action.Roll ||
                            packet.Action == Networking.Actions.Action.EndRolling ||
                            packet.Action == Networking.Actions.Action.SaveDie ||
                            packet.Action == Networking.Actions.Action.UnSaveDie, sendCards: true);
     }
 }
        public bool HandlePacket(XDocument doc)
        {
            Type type = ActionPacket.ByName(doc.Element("Packet").Attribute("Type").Value);

            if (type == null)
            {
                return(false);
            }
            var packet = (ActionPacket)Activator.CreateInstance(type);

            try
            {
                packet.Deserialize(doc);
            }
            catch
            {
                return(false);
            }
            packet.Execute();
            return(true);
        }
예제 #7
0
        /// <summary>
        /// Sends local action to server to update the game status
        /// </summary>
        /// <param name="packet"></param>
        public static void SendActionPacket(ActionPacket packet)
        {
            if (!MainGameScreen.gameOver)
            {
                while (!CanContinue)
                {
                    Thread.Sleep(500);
                    Console.WriteLine("Sleeping packet type: " + packet.Action);
                }
            }

            var outMsg = NetClient.CreateMessage();

            outMsg.Write((byte)PacketTypes.Action);
            var json = JsonConvert.SerializeObject(packet);

            JsonConvert.DeserializeObject <ActionPacket>(json);
            outMsg.Write(json);
            NetClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered);
            CanContinue = false;
        }
        /// <summary>
        /// Changes the game state with the given action.
        /// </summary>
        /// <param name="actionPacket">Action packet</param>
        public static void AcceptAction(ActionPacket actionPacket)
        {
            //if(!Game.Host) return;
            switch (actionPacket.Action)
            {
            case Action.StartTurn:
                Game.StartTurn();
                break;

            case Action.Roll:
                DiceController.Roll();
                break;

            case Action.EndRolling:
                DiceController.EndRolling();
                break;

            case Action.BuyCard:
                switch ((CardsForSale)actionPacket.Value)
                {
                case CardsForSale.One:
                    CardController.BuyCardOne();
                    break;

                case CardsForSale.Two:
                    CardController.BuyCardTwo();
                    break;

                case CardsForSale.Three:
                    CardController.BuyCardThree();
                    break;

                default:
                    return;
                }
                break;

            case Action.RemoveCard:
                Game.RemoveCard((Card)actionPacket.Value);
                break;

            case Action.EndTurn:
                Game.EndTurn();
                break;

            case Action.Yield:
                MonsterController.GetById(actionPacket.PlayerId).Yield();
                break;

            case Action.SaveDie:
                DiceController.SaveDie((int)actionPacket.Value);
                break;

            case Action.UnSaveDie:
                DiceController.UnSaveDie((int)actionPacket.Value);
                break;

            case Action.NoYield:
                MonsterController.GetById(actionPacket.PlayerId).CanYield = false;
                break;

            default:
                return;
            }
        }