void CalculateDropChance()
    {
        Data_PlayerFile_Sr zombie = RoomsManager.GetPlayerData(index);
        int dropID = 0;

        if (zombie.HPMax >= 100)
        {
            dropID = 2;
            if (zombie.HPMax >= 200)
            {
                dropID = Random.Range(2, 3);
            }
            if (zombie.HPMax >= 300)
            {
                dropID = Random.Range(3, 4);
            }

            float chance = zombie.HPMax * zombie.attackPower / (float)dropID / 1000;

            Random.seed = (int)Time.time;
            float var1 = Random.value;
            Random.seed = (int)Time.time * Random.Range(3, 7);
            float var2 = Random.value;

            if (Mathf.Abs(var1 - var2) < chance)
            {
                AccountData acc = Networking_OnConnect.GetAccountData(index);

                Player_Weapon_Sr weap = RoomsManager.InstantiateWeapon((weaponType_Sr)dropID, transform.position, acc.roomID);
                weap.DropWeapon(true);
            }
        }
    }
예제 #2
0
    static void PickUpWeapon(Player_Item_Sr item, Player_MovePlayer controll)
    {
        Player_Weapon_Sr weap = null;

        weap = item.gameObject.GetComponent <Player_Weapon_Sr>();

        if (weap)
        {
            weap.TakeWeapon(controll.weapon, controll.index);
        }
    }
예제 #3
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(item.index);
     writer.Write((int)item.ItemType);
     switch (item.ItemType)
     {
     case ItemType_Sr.weapon:
         Player_Weapon_Sr weap = (Player_Weapon_Sr)item;
         writer.Write((int)weap.WeaponType);
         writer.Write(weap.Dropped);
         if (weap.Dropped)
         {
             writer.Write(weap.transform.position);
             writer.Write(weap.transform.rotation);
         }
         else
         {
             writer.Write(weap.ShoterIndex);
         }
         break;
     }
 }
    //Add new player on map
    static void PlayerLoad(NetworkConnection con, Data_PlayerFile_Sr data, int roomID)
    {
        Room room = GetRoom(roomID);

        if (room)
        {
            GameObject go = (GameObject)Instantiate((GameObject)Resources.Load("Player"), room.spawnPosition, Quaternion.identity);
            go.name = data.nick;
            Player_MovePlayer move = go.GetComponent <Player_MovePlayer>();
            move.playerCon = con;
            PlayerConnectToRoom(roomID, data, go);

            Message_Sr.NewPlayerOnScene_Sr newPL = new Message_Sr.NewPlayerOnScene_Sr();
            newPL.player = GetPlayerData(data.sessionID);
            SendReliableToRoom(Networking_msgType_Sr.NewPlayerConnnectOnScene, newPL, roomID);

            Player_Weapon_Sr weap = InstantiateWeapon(weaponType_Sr.GaussGun, roomID);
            if (weap)
            {
                weap.TakeWeapon(move.weapon, data.sessionID);
            }
        }
    }
예제 #5
0
    public static Player_Weapon_Sr InstantiateWeapon(weaponType_Sr type, Vector3 position, int roomID)
    {
        Player_Weapon_Sr weap = null;
        GameObject       go   = null;

        switch (type)
        {
        case weaponType_Sr.Machine:
            go = (GameObject)Instantiate(Weapons[0], position, Quaternion.identity);
            break;

        case weaponType_Sr.ShotGun:
            go = (GameObject)Instantiate(Weapons[1], position, Quaternion.identity);
            break;

        case weaponType_Sr.Rifle:
            go = (GameObject)Instantiate(Weapons[2], position, Quaternion.identity);
            break;

        case weaponType_Sr.GaussGun:
            go = (GameObject)Instantiate(Weapons[3], position, Quaternion.identity);
            break;
        }

        if (go)
        {
            weap = go.GetComponent <Player_Weapon_Sr>();
            Room room = GetRoom(roomID);
            if (room)
            {
                room.AddNewItemOnScene(weap);
            }
            SendInstantiateWeapon(weap);
        }

        return(weap);
    }
예제 #6
0
 public static void SendInstantiateWeapon(Player_Weapon_Sr weapon)
 {
     Message_Sr.LoadItem_Sr item = new Message_Sr.LoadItem_Sr();
     item.item = weapon;
     SendReliableToRoom(Networking_msgType_Sr.NewItemOnScene, item, weapon.roomID);
 }
    public static void SendItems(NetworkConnection con, int sessionID)
    {
        AccountData acc  = Networking_OnConnect.GetAccountData(sessionID);
        Room        room = GetRoom(acc.roomID);

        if (room)
        {
            itemsSend  = packetItem;
            itemsSends = 0;
            if (room.itemListCount > 0)
            {
                while (!allItems)
                {
                    if (itemsSends != room.itemListCount)
                    {
                        lastItems = room.itemListCount - itemsSends;

                        NetworkWriter writer = new NetworkWriter();
                        writer.StartMessage(Networking_msgType_Sr.ItemList);

                        if (lastItems < itemsSend)
                        {
                            allItems  = true;
                            itemsSend = lastItems;
                            writer.Write(itemsSend);
                            writer.Write(true);
                        }
                        else
                        {
                            writer.Write(itemsSend);
                            writer.Write(false);
                        }
                        for (int k = 0; k < itemsSend; k++)
                        {
                            Player_Item_Sr data = room.GetItem(itemsSends);
                            if (data != null)
                            {
                                writer.Write(true);
                                writer.Write(data.index);
                                writer.Write((int)data.ItemType);

                                switch (data.ItemType)
                                {
                                case ItemType_Sr.weapon:
                                    writer.Write((int)data.WeaponType);
                                    Player_Weapon_Sr weap = data.gameObject.GetComponent <Player_Weapon_Sr>();
                                    writer.Write(weap.Dropped);
                                    if (weap.Dropped)
                                    {
                                        writer.Write(data.transform.position);
                                        writer.Write(data.transform.rotation);
                                    }
                                    else
                                    {
                                        writer.Write(weap.ShoterIndex);
                                        if (weap.ShoterIndex == sessionID)
                                        {
                                            writer.Write(true);
                                            writer.Write(weap.maxAmmo);
                                        }
                                        else
                                        {
                                            writer.Write(false);
                                        }
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                writer.Write(false);
                            }
                            itemsSends++;
                        }
                        writer.FinishMessage();
                        con.SendWriter(writer, 0);
                    }
                    else
                    {
                        allItems = true;
                    }
                }
            }
            else
            {
                NetworkWriter writer = new NetworkWriter();
                writer.StartMessage(Networking_msgType_Sr.ItemList);
                writer.Write(0);
                writer.Write(true);
                writer.FinishMessage();
                con.SendWriter(writer, 0);
            }
            allItems = false;
        }
    }