コード例 #1
0
ファイル: Inventory.cs プロジェクト: Horsuna/server
    public void tryAddItem(int id, int amount)
    {
        if (ItemWeight.getWeight(id) != -1000)
        {
            ServerItem serverItem = new ServerItem(id, ItemAmount.getAmount(id), ItemState.getState(id), Vector3.zero);
            Vector3    position   = base.transform.position;

            if (base.GetComponent <Player>().vehicle != null)
            {
                position = base.GetComponent <Player>().vehicle.getPosition();
            }

            for (int i = 0; i < amount; i++)
            {
                if (this.hasSpace(serverItem) != 0)
                {
                    SpawnItems.dropItem(id, position);
                }
                else
                {
                    this.addItem(serverItem);
                }
            }
        }
    }
コード例 #2
0
    public void tellBackpack(int setBackpack, NetworkMessageInfo info)
    {
        /*if (HackCheck(info))
         *  return;*/

        if (Network.isServer && this.backpack != -1 && ItemType.getType(this.backpack) == 2)
        {
            SpawnItems.dropItem(this.backpack, base.transform.position);
        }
        this.backpack = setBackpack;
        if (this.character != null)
        {
            this.character.backpack = this.backpack;
            this.character.wear();
        }
        if (Network.isServer)
        {
            base.GetComponent <Inventory>().resize(BagSize.getWidth(this.backpack), BagSize.getHeight(this.backpack), BagSize.getCapacity(this.backpack));
        }
    }
コード例 #3
0
ファイル: AI.cs プロジェクト: Horsuna/server
 public void damage(int amount)
 {
     if (!this.dead)
     {
         AI aI = this;
         aI.health = aI.health - amount;
         if (this.health <= 0)
         {
             base.networkView.RPC("tellDead", RPCMode.All, new object[0]);
             if (UnityEngine.Random.@value > this.chanceDrop)
             {
                 for (int i = 0; i < UnityEngine.Random.Range(this.minDrops, this.maxDrops + 1); i++)
                 {
                     SpawnItems.dropItem(Loot.getLoot(this.loot), base.transform.position);
                 }
             }
             base.transform.rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f);
             base.Invoke("respawn", (float)UnityEngine.Random.Range(100, 140));
         }
     }
 }
コード例 #4
0
    public void drop()
    {
        Vector3 position = base.transform.position;

        if (base.GetComponent <Player>().vehicle != null)
        {
            position = base.GetComponent <Player>().vehicle.getPosition();
        }
        if (this.shirt != -1)
        {
            SpawnItems.dropItem(this.shirt, position);
        }
        if (this.pants != -1)
        {
            SpawnItems.dropItem(this.pants, position);
        }
        if (this.hat != -1)
        {
            SpawnItems.dropItem(this.hat, position);
        }
        if (this.backpack != -1)
        {
            SpawnItems.dropItem(this.backpack, position);
        }
        if (this.vest != -1)
        {
            SpawnItems.dropItem(this.vest, position);
        }
        this.shirt    = -1;
        this.pants    = -1;
        this.hat      = -1;
        this.backpack = -1;
        this.vest     = -1;
        this.item     = -1;
        this.state    = string.Empty;
        base.networkView.RPC("tellAllClothes", RPCMode.All, new object[] { this.face, this.shirt, this.pants, this.hat, this.hair, this.backpack, this.vest, this.item, this.state, this.skinColor, this.hairColor, this.arm });
    }
コード例 #5
0
 public static void chop(int index, int amount, GameObject killer)
 {
     if (SpawnResources.health[index] > 0)
     {
         SpawnResources.health[index] = SpawnResources.health[index] - amount;
         if (SpawnResources.health[index] <= 0)
         {
             if (killer != null)
             {
                 killer.GetComponent <Skills>().learn(UnityEngine.Random.Range(2, 5));
                 if (!killer.networkView.isMine)
                 {
                     killer.networkView.RPC("collectedResource", killer.networkView.owner, new object[0]);
                 }
                 else
                 {
                     killer.GetComponent <Player>().collectedResource();
                 }
             }
             NetworkEffects.askEffect(string.Concat("Effects/", SpawnResources.model.transform.GetChild(index).GetChild(0).name), SpawnResources.model.transform.GetChild(index).position + new Vector3(0f, 2f, 0f), Quaternion.Euler(-90f, 0f, 0f), -1f);
             string  child   = SpawnResources.model.transform.GetChild(index).GetChild(0).name;
             Vector3 vector3 = SpawnResources.model.transform.GetChild(index).position;
             SpawnResources.tool.delete(index);
             SpawnResources.tool.networkView.RPC("delete", RPCMode.OthersBuffered, new object[] { index });
             if (child.Substring(0, 4) != "rock")
             {
                 NetworkSounds.askSound("Sounds/Resources/timber", vector3, 1f, UnityEngine.Random.Range(0.9f, 1.1f), 2f);
                 for (int i = 0; i < UnityEngine.Random.Range(6, 10); i++)
                 {
                     float single  = UnityEngine.Random.Range(0f, 5.28f);
                     float single1 = UnityEngine.Random.@value;
                     if ((double)single1 > 0.975)
                     {
                         SpawnItems.dropItem(8018, vector3 + new Vector3(Mathf.Sin(single) * 2.5f, 1f, Mathf.Cos(single) * 2.5f));
                     }
                     else if ((double)single1 <= 0.5)
                     {
                         SpawnItems.dropItem(18003, vector3 + new Vector3(Mathf.Sin(single) * 2.5f, 1f, Mathf.Cos(single) * 2.5f));
                     }
                     else
                     {
                         SpawnItems.dropItem(18004, vector3 + new Vector3(Mathf.Sin(single) * 2.5f, 1f, Mathf.Cos(single) * 2.5f));
                     }
                 }
                 if (child == "palm_0")
                 {
                     for (int j = 0; j < UnityEngine.Random.Range(2, 4); j++)
                     {
                         float single2 = UnityEngine.Random.Range(0f, 5.28f);
                         SpawnItems.dropItem(14031, vector3 + new Vector3(Mathf.Sin(single2) * 2.5f, 1f, Mathf.Cos(single2) * 2.5f));
                     }
                 }
             }
             else
             {
                 NetworkSounds.askSound("Sounds/Resources/smash", vector3, 1f, UnityEngine.Random.Range(0.9f, 1.1f), 2f);
                 for (int k = 0; k < UnityEngine.Random.Range(6, 10); k++)
                 {
                     float single3 = UnityEngine.Random.Range(0f, 5.28f);
                     if ((double)UnityEngine.Random.@value <= 0.75)
                     {
                         SpawnItems.dropItem(18019, vector3 + new Vector3(Mathf.Sin(single3) * 4f, 1f, Mathf.Cos(single3) * 4f));
                     }
                     else
                     {
                         SpawnItems.dropItem(18015, vector3 + new Vector3(Mathf.Sin(single3) * 4f, 1f, Mathf.Cos(single3) * 4f));
                     }
                 }
             }
         }
     }
 }
コード例 #6
0
 public void Update()
 {
     if (base.networkView.isMine)
     {
         if ((Player.life.dead || Movement.isSwimming || Movement.isClimbing || Movement.isDriving) && Equipment.model != null)
         {
             Equipment.dequip();
         }
         if (Equipment.model != null)
         {
             if (!Equipment.ready)
             {
                 Equipment.ready = true;
                 Equipment.model.transform.FindChild("model").renderer.enabled = true;
                 Equipment.useable.equip();
                 Equipment.ticking = true;
             }
             else if (Equipment.ticking)
             {
                 if (Equipment.setup)
                 {
                     Equipment.useable.tick();
                 }
                 else if (Time.realtimeSinceStartup - Equipment.startedEquip > Viewmodel.model.animation["equip"].length)
                 {
                     Equipment.setup = true;
                 }
             }
             if (Input.GetKeyDown(InputSettings.dropKey))
             {
                 int num  = Equipment.equipped.x;
                 int num1 = Equipment.equipped.y;
                 Equipment.dequip();
                 SpawnItems.dropItem(num, num1, Input.GetKey(InputSettings.otherKey));
             }
             else if (Input.GetKeyDown(InputSettings.itemKey))
             {
                 Equipment.dequip();
             }
         }
         if (Screen.lockCursor && !Player.life.dead)
         {
             if (Input.GetKeyDown(KeyCode.Alpha1))
             {
                 Equipment.equip(0, 0);
             }
             if (Input.GetKeyDown(KeyCode.Alpha2))
             {
                 Equipment.equip(1, 0);
             }
             if (Input.GetKeyDown(KeyCode.Alpha3))
             {
                 Equipment.equip(2, 0);
             }
             if (Input.GetKeyDown(KeyCode.Alpha4))
             {
                 Equipment.equip(3, 0);
             }
             if (Input.GetKeyDown(KeyCode.Alpha5))
             {
                 Equipment.equip(4, 0);
             }
             if (Input.GetKeyDown(KeyCode.Alpha6))
             {
                 Equipment.equip(5, 0);
             }
             if (!Equipment.busy && Equipment.setup)
             {
                 if (Equipment.useable != null)
                 {
                     if (Input.GetKeyDown(InputSettings.shootKey))
                     {
                         Equipment.useable.startPrimary();
                     }
                     if (Input.GetKeyUp(InputSettings.shootKey))
                     {
                         Equipment.useable.stopPrimary();
                     }
                     if (Input.GetKeyDown(InputSettings.aimKey))
                     {
                         Equipment.useable.startSecondary();
                     }
                     if (Input.GetKeyUp(InputSettings.aimKey))
                     {
                         Equipment.useable.stopSecondary();
                     }
                 }
                 else if (!Player.life.dead && !Movement.isSwimming && !Movement.isClimbing && Movement.vehicle == null && Stance.state != 2)
                 {
                     if (Input.GetKeyDown(InputSettings.shootKey) && !this.swinging)
                     {
                         this.swinging = true;
                         this.right    = false;
                     }
                     if (Input.GetKeyDown(InputSettings.aimKey) && !this.swinging)
                     {
                         this.swinging = true;
                         this.right    = true;
                     }
                 }
             }
         }
         if (this.swung && Time.realtimeSinceStartup - this.lastSwing > Viewmodel.model.animation["punchRight"].length / 2f)
         {
             NetworkSounds.askSound("Sounds/Items/8001/use", Camera.main.transform.position + (Camera.main.transform.forward * 0.5f), 0.25f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
             this.swung = false;
             Physics.Raycast(Camera.main.transform.position + (Camera.main.transform.forward * -0.5f), Camera.main.transform.forward, out Equipment.hit, 2f, RayMasks.DAMAGE);
             if (Equipment.hit.collider != null)
             {
                 if (Equipment.hit.point.y < Ocean.level)
                 {
                     NetworkSounds.askSound("Sounds/Impacts/rock", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/bubbles", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.gameObject.name == "ground" || Equipment.hit.collider.material.name.ToLower() == "rock (instance)" || Equipment.hit.collider.material.name.ToLower() == "ground (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/rock", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/rock", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "cloth (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/concrete", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/cloth", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "wood (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/wood", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/splinters", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "tile (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/concrete", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/tile", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "concrete (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/concrete", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/concrete", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "metal (instance)" || Equipment.hit.collider.material.name.ToLower() == "iron (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/metal", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/sparks", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 else if (Equipment.hit.collider.material.name.ToLower() == "flesh (instance)")
                 {
                     NetworkSounds.askSound("Sounds/Impacts/flesh", Equipment.hit.point, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 0.25f);
                     NetworkEffects.askEffect("Effects/flesh", Equipment.hit.point + (Equipment.hit.normal * 0.05f), Quaternion.LookRotation(Equipment.hit.normal), -1f);
                 }
                 if (Equipment.hit.collider.tag == "Enemy" && ServerSettings.pvp)
                 {
                     int        limb  = OwnerFinder.getLimb(Equipment.hit.collider.gameObject);
                     GameObject owner = OwnerFinder.getOwner(Equipment.hit.collider.gameObject);
                     if (owner != null && owner.GetComponent <Player>().action != 4 && (PlayerSettings.friend == string.Empty || PlayerSettings.friendHash != owner.GetComponent <Player>().owner.friend))
                     {
                         if (!Network.isServer)
                         {
                             base.networkView.RPC("punchPlayer", RPCMode.Server, new object[] { owner.GetComponent <Player>().owner.id, limb });
                         }
                         else
                         {
                             this.punchPlayer(owner.GetComponent <Player>().owner.id, limb);
                         }
                     }
                 }
                 else if (Equipment.hit.collider.tag == "Animal")
                 {
                     int        limb1      = OwnerFinder.getLimb(Equipment.hit.collider.gameObject);
                     GameObject gameObject = OwnerFinder.getOwner(Equipment.hit.collider.gameObject);
                     if (gameObject != null && !gameObject.GetComponent <AI>().dead)
                     {
                         if (!Network.isServer)
                         {
                             base.networkView.RPC("punchAnimal", RPCMode.Server, new object[] { gameObject.networkView.viewID, limb1 });
                         }
                         else
                         {
                             this.punchAnimal(gameObject.networkView.viewID, limb1);
                         }
                     }
                 }
             }
         }
         if (!this.swinging || Time.realtimeSinceStartup - this.lastSwing <= Viewmodel.model.animation["punchRight"].length)
         {
             this.swinging = false;
         }
         else
         {
             this.swinging  = false;
             this.lastSwing = Time.realtimeSinceStartup;
             this.swung     = true;
             if (!this.right)
             {
                 Viewmodel.play("punchLeft");
                 if (Stance.state == 0)
                 {
                     Player.play("standPunchLeft");
                 }
                 else if (Stance.state == 1)
                 {
                     Player.play("crouchPunchLeft");
                 }
             }
             else
             {
                 Viewmodel.play("punchRight");
                 if (Stance.state == 0)
                 {
                     Player.play("standPunchRight");
                 }
                 else if (Stance.state == 1)
                 {
                     Player.play("crouchPunchRight");
                 }
             }
         }
     }
 }