send_next_packet() public static méthode

public static send_next_packet ( DataType, type, int id, string>.List memersToSend, Protocol, protocol ) : string
type DataType,
id int
memersToSend string>.List
protocol Protocol,
Résultat string
Exemple #1
0
 //Called every frame
 void Update()
 {
     if (Input.GetKey(KeyCode.Mouse0) && attackReady)
     {
         //left click attack
         attackReady = false;
         var   dir   = ((Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position)).normalized;
         float delay = player.basicAttack(dir);
         Invoke("enableAttack", delay);
         NetworkingManager.send_next_packet(DataType.Trigger, player.playerID, new List <Pair <string, string> > {
             new Pair <string, string>("Attack", "0"),
             new Pair <string, string>("DirectionX", dir.x.ToString()),
             new Pair <string, string>("DirectionY", dir.y.ToString())
         });
     }
     else if (Input.GetKey(KeyCode.Mouse1) && attackReady && specialReady)
     {
         //right click attack
         attackReady  = false;
         specialReady = false;
         var     dir   = ((Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position)).normalized;
         float[] delay = player.specialAttack(dir);
         Invoke("enableAttack", delay[0]);
         Invoke("enableSpecial", delay[1]);
         NetworkingManager.send_next_packet(DataType.Trigger, player.playerID, new List <Pair <string, string> > {
             new Pair <string, string>("Attack", "1"),
             new Pair <string, string>("DirectionX", dir.x.ToString()),
             new Pair <string, string>("DirectionY", dir.y.ToString()),
         });
     }
 }
Exemple #2
0
    /*---------------------------------------------------------------------------------------------------------------------
    *  -- FUNCTION:    SendLaserPacket
    *  --
    *  -- DATE:        March 16, 2016
    *  --
    *  -- REVISIONS:
    *  --
    *  -- DESIGNER:    Carson Roscoe
    *  --
    *  -- PROGRAMMER:  Carson Roscoe
    *  --
    *  -- INTERFACE:   void SendLaserPacket()
    *  --
    *  -- RETURNS:     void
    *  --
    *  -- NOTES:
    *  --  Sends a packet to the networking manager to tell it that you have fired a gunner special shot.
    *  ---------------------------------------------------------------------------------------------------------------------*/
    void SendLaserPacket()
    {
        var member = new List <Pair <string, string> >();

        member.Add(new Pair <string, string>("playerID", playerID.ToString()));
        NetworkingManager.send_next_packet(DataType.SpecialCase, (int)SpecialCase.GunnerSpecial, member, Protocol.UDP);
    }
Exemple #3
0
    /*---------------------------------------------------------------------------------------
     * -- FUNCTION:     OkDropButtonOnClick
     * -- DATE:         10/03/2016
     * -- REVISIONS:
     * -- DESIGNER:     Joseph Tam-Huang
     * -- PROGRAMMER:   Joseph Tam-Huang
     * -- INTERFACE:    public void OkDropButtonOnClick()
     * -- RETURNS:  void
     * -- NOTES:
     * -- Checks that the amount trying to be dropped is allowed. If yes, send a DropItem
     * -- network message, otherwise update the error message.
     * ----------------------------------------------------------------------------------------*/
    public void OkDropButtonOnClick()
    {
        Debug.Log("ok drop clicked");
        _drop_amt = int.Parse(_amt_input_field.GetComponent <InputField>().text);
        if (_drop_amt > 0 && _drop_amt <= _amt)
        {
            // Send Network message
            List <Pair <string, string> > msg =
                _world_item_manager.CreateDropItemNetworkMessage(_item.id, _drop_amt, _inv_pos);
            NetworkingManager.send_next_packet(DataType.Item, (int)ItemUpdate.Drop, msg, Protocol.TCP);

            // Pretend that a drop message was received
            if (Application.platform != RuntimePlatform.LinuxPlayer)
            {
                _world_item_manager.ReceiveItemDropPacket(_world_item_manager.ConvertListToJSONClass(msg));
            }

            GameData.MouseBlocked = false;
            Deactivate();
        }
        else
        {
            _error_text.text = "Invalid amount";
        }
    }
Exemple #4
0
    /*--------------------------------------------------------------------------------------
     * -- FUNCTION:     OnTriggerEnter2D
     * -- DATE:         05/03/2016
     * -- REVISIONS:
     * -- DESIGNER:     Joseph Tam-Huang
     * -- PROGRAMMER:   Joseph Tam-Huang
     * -- INTERFACE:    void OnTriggerEnter2D(Collider2D other)
     * --                  Collider2D other: The collider box of the other GameObject
     * -- RETURNS:  void
     * -- NOTES:
     * -- The trigger_entered flag is enabled when the player comes into contact with the
     * -- collider box of the world item for the first time.
     * -----------------------------------------------------------------------------------------*/
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player" &&
            other.gameObject.GetComponent <BaseClass>().playerID == GameData.MyPlayer.PlayerID)
        {
            _trigger_entered = true;

            // Send item pickup message once if gold
            if (Inventory.instance.CheckIfItemCanBeAdded(item.stackable, item.id))
            {
                if (autolootable)
                {
                    int player_id = GameData.MyPlayer.PlayerID;
                    List <Pair <string, string> > msg = new List <Pair <string, string> >();
                    msg = _world_item_manager.CreatePickupItemNetworkMessage(world_item_id, player_id, item.id, amount);
                    NetworkingManager.send_next_packet(DataType.Item, (int)ItemUpdate.Pickup, msg, Protocol.TCP);

                    _tooltip.Deactivate();

                    // Pretend that a pickup event was received
                    if (Application.platform != RuntimePlatform.LinuxPlayer)
                    {
                        StartCoroutine(WorldItemManager.Instance.WaitSmallDelayBeforeReceivePickupPacket(WorldItemManager.Instance.ConvertListToJSONClass(msg)));
                    }
                }
            }
            else
            {
                StartCoroutine(Inventory.instance.DisplayInventoryFullError());
            }
        }
    }
Exemple #5
0
    /*----------------------------------------------------------------------------
     * --	Attempt to place a building to where the mouse is at when an left click
     * --  event is triggered. Assigns the corresponding attributes to the Building
     * --  component.
     * --	Interface:  private bool PlaceBuilding(GameObject building)
     * --					[building] Building that will be placed
     * --	programmer: Jerry Jia, Thomas Yu
     * --	@return: void
     * ------------------------------------------------------------------------------*/
    private bool PlaceBuilding(GameObject building)
    {
        // Construct a vector of where the Gameobject will be placed
        Vector3 buildingLocation = new Vector3((int)currFramePosition.x, (int)currFramePosition.y, -2);

        // Check if it is a valid location to place the building
        if (!CheckValidLocation(building))
        {
            return(false);
        }


        // Set the color transparency
        shop.Selected.Building.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);

        SetAllCollidersStatus(building, true);


        // Indicate that the item has been successfully bought and placed
        ItemBought = false;

        //weird merge conflict here (END)
        placementRange.SetActive(false);

        print("x: " + building.transform.rotation.x + " y: " + building.transform.rotation.y + " z: " + building.transform.rotation.z);
        if (Application.platform == RuntimePlatform.LinuxPlayer)
        {
            // Send the packet, with Team ID, user name, and the message input
            List <Pair <string, string> > packetData = new List <Pair <string, string> >();
            packetData.Add(new Pair <string, string>(NetworkKeyString.TeamID, GameData.MyPlayer.TeamID.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.XPos, buildingLocation.x.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.YPos, buildingLocation.y.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.ZPos, buildingLocation.z.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.XRot, building.transform.rotation.x.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.YRot, building.transform.rotation.y.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.ZRot, building.transform.eulerAngles.z.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.BuildType, ((int)buildType).ToString()));
            var packet = NetworkingManager.send_next_packet(DataType.UI, (int)UICode.BuildingCreation, packetData, Protocol.NA);
            Send(packet);
        }
        else
        {
            GameObject testBuild = (GameObject)Instantiate(building, buildingLocation, building.transform.rotation);
            testBuild.GetComponent <Building>().placing = false;
            if (testBuild.GetComponent <Building>().type == Building.BuildingType.Turret)
            {//
                testBuild.GetComponent <AI>().instantTurret(2, 40, 2, 15, 15);

                //testBuild.GetComponent<AI>().instantTurret(2, 40, GameData.MyPlayer.TeamID, 15, 15);
                Debug.Log("Instant turret 2");
            }
        }

        Destroy(building);
        return(true);
    }
Exemple #6
0
    /*------------------------------------------------------------------------------------------------------------------
     * -- FUNCTION:     SendMessageToServer
     * -- DATE:         April 5, 2016
     * -- REVISIONS:    N/A
     * -- DESIGNER:    Krystle Bulalakaw
     * -- PROGRAMMER:  Krystle Bulalakaw
     * -- INTERFACE:    void SendMessageToServer(List<Pair<string, string>> msg, int eventType)
     * --                      List<Pair<string, string>> msg - the message to send
     * --                      int eventType                  - the item event type
     * -- RETURNS:  List<Pair<string, string>>   - List of map event data
     * -- NOTES:
     * -- Sends a message to the server via Networking Manager's send_next_packet call.
     * ----------------------------------------------------------------------------------------------------------------------*/
    void SendMessageToServer(List <Pair <string, string> > msg, int eventType)
    {
        var packet = NetworkingManager.send_next_packet(DataType.Item, eventType, msg, Protocol.TCP);

        if (Application.platform != RuntimePlatform.LinuxPlayer)
        {
            string temp = "[" + packet + "]";
            NetworkingManager.instance.update_data(temp);
        }
    }
Exemple #7
0
    public static void SendLobbyData(NetworkCode code)
    {
        // Construct json packet
        List <Pair <string, string> > packetData = new List <Pair <string, string> >();

        if (code != NetworkCode.PlayerJoinedLobby)
        {
            packetData.Add(new Pair <string, string>(NetworkKeyString.PlayerID, GameData.MyPlayer.PlayerID.ToString()));
        }

        switch (code)
        {
        case NetworkCode.TeamChangeRequest:
            packetData.Add(new Pair <string, string>(NetworkKeyString.TeamID, GameData.MyPlayer.TeamID.ToString()));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.TeamChangeRequest, packetData, Protocol.NA));
            break;

        case NetworkCode.ClassChangeRequest:
            packetData.Add(new Pair <string, string>(NetworkKeyString.ClassID, ((int)GameData.MyPlayer.ClassType).ToString()));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.ClassChangeRequest, packetData, Protocol.NA));
            break;

        case NetworkCode.ReadyRequest:
            packetData.Add(new Pair <string, string>(NetworkKeyString.Ready, GameData.MyPlayer.Ready ? "1" : "0"));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.ReadyRequest, packetData, Protocol.NA));
            break;

        case NetworkCode.PlayerJoinedLobby:
            packetData.Add(new Pair <string, string>(NetworkKeyString.UserName, "\"" + GameData.MyPlayer.Username + "\""));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.PlayerJoinedLobby, packetData, Protocol.NA));
            break;

        case NetworkCode.PlayerLeftLobby:
            SendingPacket = NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.PlayerLeftLobby, packetData, Protocol.NA);
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.PlayerLeftLobby, packetData, Protocol.NA));
            break;

        case NetworkCode.GameStart:
            SendingPacket = NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.GameStart, packetData, Protocol.NA);
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.GameStart, packetData, Protocol.NA));
            break;

        // NOTE:: Send packet indicating the team that slected the aman
        case NetworkCode.AmanSelection:
            packetData.Add(new Pair <string, string>(NetworkKeyString.TeamID, GameData.MyPlayer.TeamID.ToString()));
            packetData.Add(new Pair <string, string>(NetworkKeyString.AmanID, GameData.AllyKingID.ToString()));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.AmanSelection, packetData, Protocol.NA));
            break;

        case NetworkCode.ThemeSelection:
            packetData.Add(new Pair <string, string>(NetworkKeyString.Theme, ((int)GameData.CurrentTheme).ToString()));
            Send(NetworkingManager.send_next_packet(DataType.Lobby, (int)NetworkCode.ThemeSelection, packetData, Protocol.NA));
            break;
        }
    }
Exemple #8
0
    /*------------------------------------------------------------------------------------------------------------------
     * -- FUNCTION:     SendMessageToServer
     * -- DATE:         April 1, 2016
     * -- REVISIONS:    N/A
     * -- DESIGNER:    Krystle Bulalakaw
     * -- PROGRAMMER:  Krystle Bulalakaw
     * -- INTERFACE:    void SendMessageToServer(List<Pair<string, string>> msg, int eventType)
     * --                      List<Pair<string, string>> msg - the message to send
     * --                      int eventType                  - the map event type
     * -- RETURNS:  List<Pair<string, string>>   - List of map event data
     * -- NOTES:
     * -- Sends a message to the server via Networking Manager's send_next_packet call.
     * ----------------------------------------------------------------------------------------------------------------------*/
    void SendMessageToServer(List <Pair <string, string> > msg, int eventType)
    {
        var    packet = NetworkingManager.send_next_packet(DataType.Environment, eventType, msg, Protocol.TCP);
        string temp   = "[" + packet + "]";       // Wrap JSON child into array

        // Fakes network data updates for local testing. Comment this line when actually testing on network.
        if (Application.platform != RuntimePlatform.LinuxPlayer)
        {
            NetworkingManager.instance.update_data(temp);
        }
    }
Exemple #9
0
        /*---------------------------------------------------------------------------------------------------------------------
        *  -- METHOD: update_stats
        *  --
        *  -- DATE: March 16, 2016
        *  --
        *  -- REVISIONS:
        *  --
        *  -- DESIGNER: Allen Tsang, Carson Roscoe
        *  --
        *  -- PROGRAMMER: Allen Tsang, Carson Roscoe
        *  --
        *  -- INTERFACE: void update_stats()
        *  --
        *  -- RETURNS: void
        *  --
        *  -- NOTES:
        *  -- Sends stat updates to the networking manager to notify other players that your base stats have changed.
        *  ---------------------------------------------------------------------------------------------------------------------*/
        public void update_stats()
        {
            if (_playerID != GameData.MyPlayer.PlayerID)
            {
                return;
            }
            List <Pair <string, string> > memers = new List <Pair <string, string> >();

            memers.Add(new Pair <string, string>("AtkPower", AtkPower.ToString()));
            memers.Add(new Pair <string, string>("Defense", Defense.ToString()));
            //NetworkingManager.send_next_packet(DataType.StatUpdate, _playerID, memers, Protocol.TCP));
            Debug.Log(NetworkingManager.send_next_packet(DataType.StatUpdate, _playerID, memers, Protocol.TCP));
        }
Exemple #10
0
    /*----------------------------------------------------------------------------
     * --	Called when a building is destroyed, sends packet to the network
     * --
     * --	Interface: public void	notifydeath()
     * --
     * --	programmer: Jerry Jia
     * --	@return: void
     * ------------------------------------------------------------------------------*/
    public void     notifydeath()
    {
        // Send the packet, with Team ID, user name, and the message input
        List <Pair <string, string> > packetData = new List <Pair <string, string> >();

        packetData.Add(new Pair <string, string>(NetworkKeyString.XPos, transform.position.x.ToString()));
        packetData.Add(new Pair <string, string>(NetworkKeyString.YPos, transform.position.y.ToString()));
        packetData.Add(new Pair <string, string>(NetworkKeyString.ZPos, transform.position.z.ToString()));

        var packet = NetworkingManager.send_next_packet(DataType.UI, (int)UICode.BuildingDestruction, packetData, Protocol.TCP);

        NetworkingManager.send_next_packet(DataType.UI, (int)UICode.BuildingDestruction, packetData, Protocol.TCP);
    }
Exemple #11
0
    /*---------------------------------------------------------------------------------------------------------------------
    *  -- FUNCTION: Update
    *  --
    *  -- DATE: March 9, 2016
    *  --
    *  -- REVISIONS: None
    *  --
    *  -- DESIGNER: Hank Lo, Allen Tsang
    *  --
    *  -- PROGRAMMER: Hank Lo, Allen Tsang
    *  --
    *  -- INTERFACE: void Update(void)
    *  --
    *  -- RETURNS: void
    *  --
    *  -- NOTES:
    *  -- Called every frame. We deal with checking whether or not the mouse is pressed, or which mouse key is pressed.
    *  ---------------------------------------------------------------------------------------------------------------------*/
    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0) && attackReady && !GameData.MouseBlocked &&
            (Input.mousePosition.x < InvLeftEdge || Input.mousePosition.y > InvTopEdge))
        {
            //if (Input.GetKey(KeyCode.Mouse0) && attackReady && !GameData.MouseBlocked) {

            //left click attack

            HUD_Manager.instance.UseMainSkill(player.cooldowns[0]);
            attackReady = false;
            //var dir = ((Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position)).normalized;
            var dir = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);

            Vector2 playerLoc = (Vector2)GameData.PlayerPosition[GameData.MyPlayer.PlayerID];
            float   delay     = player.basicAttack(dir, playerLoc);
            Invoke("enableAttack", delay);
            NetworkingManager.send_next_packet(DataType.Trigger, player.playerID, new List <Pair <string, string> > {
                new Pair <string, string>("Attack", "0"),
                new Pair <string, string>("DirectionX", dir.x.ToString()),
                new Pair <string, string>("DirectionY", dir.y.ToString())
            }, Protocol.UDP);
        }

        if (Input.GetKey(KeyCode.Mouse1) && specialReady && !GameData.MouseBlocked &&
            (Input.mousePosition.x < InvLeftEdge || Input.mousePosition.y > InvTopEdge))
        {
            //right click attack
            HUD_Manager.instance.UseSubSkill(player.cooldowns[1]);
            specialReady = false;
            //var dir = ((Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position)).normalized;
            var     dir       = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 playerLoc = (Vector2)GameData.PlayerPosition[GameData.MyPlayer.PlayerID];
            float   delay     = player.specialAttack(dir, playerLoc);
            Invoke("enableSpecial", delay);
            NetworkingManager.send_next_packet(DataType.Trigger, player.playerID, new List <Pair <string, string> > {
                new Pair <string, string>("Attack", "1"),
                new Pair <string, string>("DirectionX", dir.x.ToString()),
                new Pair <string, string>("DirectionY", dir.y.ToString()),
            }, Protocol.UDP);
        }
    }
Exemple #12
0
    /*--------------------------------------------------------------------------------------
     * -- FUNCTION:     Update
     * -- DATE:         05/03/2016
     * -- REVISIONS:    27/03/2016 - Add gurad to prevent mulitple unique items from being
     * --                           picked up at once.
     * -- DESIGNER:     Joseph Tam-Huang
     * -- PROGRAMMER:   Joseph Tam-Huang
     * -- INTERFACE:    void Update()
     * -- RETURNS:  void
     * -- NOTES:
     * -- If the 'F' key is pressed while the player is in the world item object's collider box,
     * -- an message is sent to the server to signal a pick up event.
     * -- Cannot pick up more than one item even when their collider boxes overlap.
     * -----------------------------------------------------------------------------------------*/
    void Update()
    {
        // Manually pick up items that are not autolootable
        if (_trigger_entered && !autolootable && Input.GetKeyDown(KeyCode.F))
        {
            if (Inventory.instance.CheckIfItemCanBeAdded(item.stackable, item.id))
            {
                int player_id = GameData.MyPlayer.PlayerID;
                List <Pair <string, string> > msg = new List <Pair <string, string> >();

                if (!GameData.ItemCollided)
                {
                    GameData.ItemCollided = true;
                    _first_collision      = true;
                }

                if (_first_collision)
                {
                    _first_collision = false;
                    if (_world_item_manager == null)
                    {
                        Debug.Log("[ERROR] WorldItemData's Update says _world_item_manager is null");
                        return;
                    }
                    msg = _world_item_manager.CreatePickupItemNetworkMessage(world_item_id, player_id, item.id, amount);
                    NetworkingManager.send_next_packet(DataType.Item, (int)ItemUpdate.Pickup, msg, Protocol.TCP);
                    StartCoroutine(NeverReceivedPickupMessageBack());

                    // Pretend that a pickup event was received
                    if (Application.platform != RuntimePlatform.LinuxPlayer)
                    {
                        StartCoroutine(WorldItemManager.Instance.WaitSmallDelayBeforeReceivePickupPacket(WorldItemManager.Instance.ConvertListToJSONClass(msg)));
                    }
                }
                _tooltip.Deactivate();
            }
            else
            {
                StartCoroutine(Inventory.instance.DisplayInventoryFullError());
            }
        }
    }
Exemple #13
0
    /*------------------------------------------------------------------------------------------------------------------
     * -- FUNCTION:     DropGold
     * -- DATE:         March 30, 2016
     * -- REVISIONS:    April 5 - Move addition of magnetize component to CreateWorldItem()
     * -- DESIGNER:     Krystle Bulalakaw
     * -- PROGRAMMER:   Krystle Bulalakaw
     * -- INTERFACE:    DropGold(int amount)
     * --					int amount - amount of gold to drop
     * -- RETURNS:  void.
     * -- NOTES:
     * -- Creates a gold world item with some amount.
     * -- Its X and Y position is offset so that it doesn't drop in the same spot every time, and so it is easier to pick
     * -- up (not right in the center of the tree).
     * ----------------------------------------------------------------------------------------------------------------------*/
    public void DropGold(int amount)
    {
        float offset      = 1.5f;
        float offsetX     = Random.Range(-offset, offset);
        float offsetY     = Random.Range(-offset, offset);
        int   instance_id = WorldItemManager.Instance.GenerateWorldItemId();
        int   gold_id     = 2;

        List <Pair <string, string> > msg =
            WorldItemManager.Instance.CreateWorldItemNetworkMessage(instance_id, gold_id,
                                                                    amount, x + offsetX, y + offsetY);

        NetworkingManager.send_next_packet(DataType.Item, (int)ItemUpdate.Create, msg, Protocol.TCP);

        // Pretend that a drop message was received
        if (Application.platform != RuntimePlatform.LinuxPlayer)
        {
            WorldItemManager.Instance.ReceiveCreateWorldItemPacket(WorldItemManager.Instance.ConvertListToJSONClass(msg));
        }
    }
Exemple #14
0
    /*---------------------------------------------------------------------------------------------------------------------
    *  -- METHOD: PlayerDied
    *  --
    *  -- DATE: March 25th, 2016
    *  --
    *  -- REVISIONS: N/A
    *  --
    *  -- DESIGNER: Carson Roscoe
    *  --
    *  -- PROGRAMMER: Carson Roscoe
    *  --
    *  -- INTERFACE: void PlayerDied(void)
    *  --
    *  -- RETURNS: void
    *  --
    *  -- NOTES:
    *  -- Handles our player dying, sending out a packet telling everyone we have died, sending to the server a "Game Over"
    *  -- packet if our player is the aman, colourizing the screen and overall cleanup in regards to our player.
    *  ---------------------------------------------------------------------------------------------------------------------*/
    public void PlayerDied()
    {
        GameData.EnemyTeamKillCount++;
        NetworkingManager.send_next_packet(DataType.Killed, GameData.MyPlayer.PlayerID, new List <Pair <string, string> >(), Protocol.TCP);
        GameData.PlayerPosition.Remove(GameData.MyPlayer.PlayerID);
        GameData.GameState = GameState.Dying;
        HUD_Manager.instance.colourizeScreen.PlayerDied();
        Debug.Log("You have died");
        instance.player = null;
        if (GameData.MyPlayer.PlayerID == GameData.AllyKingID)
        {
            NetworkingManager.TCP_Send(NetworkingManager.send_next_packet(DataType.Lobby, 10, new List <Pair <string, string> >(), Protocol.NA), 512);
            GameLost();
        }

        if (GameData.MyPlayer.PlayerID == GameData.EnemyKingID)
        {
            NetworkingManager.TCP_Send(NetworkingManager.send_next_packet(DataType.Lobby, 10, new List <Pair <string, string> >(), Protocol.NA), 512);
            GameWon();
        }
    }
Exemple #15
0
    /*-----------------------------------------------------------------------------------
     * -- FUNCTION:     DropItemOnClick
     * -- DATE:         05/03/2016
     * -- REVISIONS:
     * -- DESIGNER:     Joseph Tam-Huang
     * -- PROGRAMMER:   Joseph Tam-Huang
     * -- INTERFACE:    public void DropItemOnClick()
     * -- RETURNS:  void
     * -- NOTES:
     * -- Sends an ItemDrop network message if there is only one item or activates the
     * -- AmountPanel if there are more that 1 item stack.
     * -- Deactivates the ItemMenu
     * ----------------------------------------------------------------------------------*/
    public void DropItemOnClick()
    {
        if (_amt > 1 && _item.stackable)
        {
            _amount_panel.Activate(_item, _amt, _inv_pos);
        }
        else
        {
            // Send Network message
            List <Pair <string, string> > msg =
                _world_item_manager.CreateDropItemNetworkMessage(_item.id, _amt, _inv_pos);
            NetworkingManager.send_next_packet(DataType.Item, (int)ItemUpdate.Drop, msg, Protocol.TCP);

            // Pretend that a drop message was received for local testing
            if (Application.platform != RuntimePlatform.LinuxPlayer)
            {
                _world_item_manager.ReceiveItemDropPacket(_world_item_manager.ConvertListToJSONClass(msg));
            }
        }
        GameData.MouseBlocked = false;
        Deactivate();
    }
Exemple #16
0
    /*-------------------------------------------------------------------------------------------------------
    *  -- FUNCTION:     UseConsumable
    *  -- DATE:         30/03/2016
    *  -- REVISIONS:
    *  -- DESIGNER:     Joseph Tam-Huang
    *  -- PROGRAMMER:   Joseph Tam-Huang
    *  -- INTERFACE:    public void UseConsumable(int inv_pos, int amount = 1)
    *  --                  int inv_pos: The inventory position
    *  --                  int amt: The amount to consume
    *  -- RETURNS:  void
    *  -- NOTES:
    *  -- Applies a boost to the stats specified by the item in the inventory slot. The stat boost applied
    *  -- is communicated to the server.
    *  -------------------------------------------------------------------------------------------------------*/
    public void UseConsumable(int inv_pos, int amount = 1)
    {
        Item _item             = inventory_item_list[inv_pos];
        int  _damage_buff      = _item.damage;
        int  _armor_buff       = _item.armor;
        int  _healing_amt      = _item.health; // Assuming healing and not an increase in max health
        int  _speed_buff       = _item.speed;
        int  _duration_of_buff = _item.duration;

        if (_duration_of_buff == Constants.NOT_APPLICABLE)
        {
            // Permament stats boost
        }

        Debug.Log("item id: " + _item.id);
        Debug.Log("damage buff: " + _item.damage);
        Debug.Log("armor buff: " + _item.armor);
        Debug.Log("healing amt: " + _item.health);
        Debug.Log("speed buff: " + _item.speed);
        Debug.Log("duration of buff" + _item.duration);

        GameManager.instance.player.GetComponent <BaseClass>().UsePotion(
            _item.damage, _item.armor, _item.health, _item.speed, _item.duration);

        NetworkingManager.send_next_packet(
            DataType.Potion,
            GameData.MyPlayer.PlayerID,
            new List <Pair <string, string> > {
            new Pair <string, string>("Damage", _item.damage.ToString()),
            new Pair <string, string>("Armour", _item.armor.ToString()),
            new Pair <string, string>("Health", _item.health.ToString()),
            new Pair <string, string>("Speed", _item.speed.ToString()),
            new Pair <string, string>("Duration", _item.duration.ToString())
        },
            Protocol.UDP);

        DestroyInventoryItem(inv_pos, 1);
    }
Exemple #17
0
    /*----------------------------------------------------------------------------
     * --	Check for any events triggered in the chat box
     * --
     * --	Interface:  void CheckChatAction()
     * --
     * --	programmer: Jerry Jia
     * --	@return: void
     * ------------------------------------------------------------------------------*/
    public void CheckChatAction()
    {
        // If return key has been pressed
        if (Input.GetKeyDown(KeyCode.Return))
        {
            // See if the chat window is currently open
            if (!chat.input.IsInteractable())
            {
                // Block all other keyboard inputs
                GameData.InputBlocked = true;
                // If not then open the chat window
                chat.input.interactable = true;
                chat.input.Select();
                chat.input.ActivateInputField();
            }
            else
            {
                // Unblocck keyboard inputs
                GameData.InputBlocked = false;
                if (Application.platform == RuntimePlatform.LinuxPlayer)
                {
                    // Send the packet, with Team ID, user name, and the message input
                    List <Pair <string, string> > packetData = new List <Pair <string, string> >();
                    packetData.Add(new Pair <string, string>(NetworkKeyString.TeamID, GameData.MyPlayer.TeamID.ToString()));
                    packetData.Add(new Pair <string, string>(NetworkKeyString.UserName, "\"" + GameData.MyPlayer.Username + "\""));
                    packetData.Add(new Pair <string, string>(NetworkKeyString.Message, "\"" + chat.input.text + "\""));
                    NetworkingManager.send_next_packet(DataType.UI, (int)UICode.Chat, packetData, Protocol.TCP);
                }

                // Clear out the chat window
                chat.input.text = "";

                // Close the window
                chat.input.interactable = false;
            }
        }
    }
Exemple #18
0
    /*---------------------------------------------------------------------------------------------------------------------
    *  -- FUNCTION: OnTriggerEnter2D
    *  --
    *  -- DATE: March 9, 2016
    *  --
    *  -- REVISIONS: April 5, 2016
    *  --              - Allen: Added multihit prevention
    *  --
    *  -- DESIGNER: Hank Lo, Allen Tsang
    *  --
    *  -- PROGRAMMER: Hank Lo, Allen Tsang
    *  --
    *  -- INTERFACE: void OnTriggerEnter2D(Collider2D other)
    *  --              Collider2D other: The object we are colliding with
    *  --
    *  -- RETURNS: void
    *  --
    *  -- NOTES:
    *  -- Used to deal with collisions with players
    *  ---------------------------------------------------------------------------------------------------------------------*/
    void OnTriggerEnter2D(Collider2D other)
    {
        Trigger attack;

        if ((attack = other.gameObject.GetComponent <Trigger>()) != null)
        {
            if (attack.teamID == team || GameData.MyPlayer == null)
            {
                return;
            }

            //check for melee multihit, ignore if already in set
            if (attack is Melee && !((Melee)attack).targets.Add(gameObject))
            {
                return;
            }

            var damageTaken = 0f;
            if (playerID == GameData.MyPlayer.PlayerID)
            {
                damageTaken = doDamage(attack.damage);
            }

            if (GameData.MyPlayer == null || playerID != GameData.MyPlayer.PlayerID)
            {
                return;
            }

            var memersToSend = new List <Pair <string, string> >();
            memersToSend.Add(new Pair <string, string>("EnemyID", attack.playerID.ToString()));
            memersToSend.Add(new Pair <string, string>("NewHP", ClassStat.CurrentHp.ToString()));
            print(NetworkingManager.send_next_packet(DataType.Hit, GameData.MyPlayer.PlayerID, memersToSend, Protocol.UDP));

            return;
        }
    }