예제 #1
0
    // Take logic to replace it with the Downgrade block, matching rotations.
    private void TakeTarget(object obj)
    {
        World world = GameManager.Instance.World;

        object[]          array             = (object[])obj;
        int               clrIdx            = (int)array[0];
        BlockValue        _blockValue       = (BlockValue)array[1];
        Vector3i          vector3i          = (Vector3i)array[2];
        BlockValue        block             = world.GetBlock(vector3i);
        EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal;

        // Find the block value for the pick up value, and add it to the inventory
        BlockValue    pickUpBlock = Block.GetBlockValue(this.PickedUpItemValue);
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
        ItemStack     itemStack   = new ItemStack(pickUpBlock.ToItemValue(), 1);

        if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
        {
            uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
        }

        entityPlayerLocal.PlayOneShot("Sounds/DestroyBlock/wooddestroy1");

        // Damage the block for its full health
        this.DamageBlock(world, clrIdx, vector3i, block, block.Block.blockMaterial.MaxDamage, entityPlayerLocal.entityId, false);
    }
예제 #2
0
    public void DamageBlock(WorldBase _world, int _clrIdx, Vector3i _blockPos, Block _block, BlockValue _blockValue, ItemValue _miningTool, float _vehicleDamage)
    {
        int blockDmg = blockDamage;

        if (blockDamage > _block.MaxDamage)
        {
            blockDmg = _block.MaxDamage;
        }
        //DebugMsg("Damage Block: motion.magnitude = " + entityVehicle.motion.magnitude.ToString("0.000") + " | damage = " + Mathf.RoundToInt(blockDmg * entityVehicle.motion.magnitude).ToString("0.000"));
        //DebugMsg("Damage Block: motion.magnitude = " + entityVehicle.motion.magnitude.ToString("0.000") + " | damage = " + blockDmg.ToString());
        //DebugMsg("Damage Block: " + _block.GetBlockName() + " (" + _block.GetType().ToString() + ") | damage = " + blockDmg.ToString());
        _block.DamageBlock(_world, _clrIdx, _blockPos, _blockValue, blockDmg, entityVehicle.AttachedEntities.entityId, true);
        //_block.DamageBlock(_world, _clrIdx, _blockPos, _blockValue, Mathf.RoundToInt(blockDmg * entityVehicle.motion.magnitude), entityVehicle.AttachedEntities.entityId, true);

        //DebugMsg("Vehicle damage = " + _vehicleDamage);
        DamageVehicle(_vehicleDamage, 0f);

        if (destroyXPFactor != 0)
        {
            ItemActionAttack iat   = new ItemActionMelee();
            ItemValue        dummy = null;
            float            miningToolBlockDamage = iat.GetDamageBlock(_miningTool, entityVehicle.player, dummy);
            float            blockMaxDamage        = _block.MaxDamage;
            int skillExpMult = Mathf.RoundToInt(blockMaxDamage / miningToolBlockDamage);
            AddSkillExp(entityVehicle.player, _miningTool.type, (_blockValue.ToItemValue().ItemClass.ActionSkillExp *((skillExpMult > 0) ? skillExpMult : 1)));
        }
    }
예제 #3
0
    // Handles what happens to the contents of the box when you pick up the block.
    private void EventData_Event(object obj)
    {
        #region EventData_Event
        World             world             = GameManager.Instance.World;
        object[]          array             = (object[])obj;
        int               clrIdx            = (int)array[0];
        BlockValue        blockValue        = (BlockValue)array[1];
        Vector3i          vector3i          = (Vector3i)array[2];
        BlockValue        block             = world.GetBlock(vector3i);
        EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal;

        TileEntityLootContainer tileEntityLootContainer = world.GetTileEntity(clrIdx, vector3i) as TileEntityLootContainer;
        if (tileEntityLootContainer != null)
        {
            world.GetGameManager().DropContentOfLootContainerServer(blockValue, vector3i, tileEntityLootContainer.entityId);
        }

        // Pick up the item and put it inyor your inventory.
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
        ItemStack     itemStack   = new ItemStack(block.ToItemValue(), 1);
        if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
        {
            uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
        }
        world.SetBlockRPC(clrIdx, vector3i, BlockValue.Air);

        #endregion
    }
예제 #4
0
        public bool FillSelection(string blockNameOrId, int rotation)
        {
            BlockValue bv = BlockUtils.GetBlockValueByNameOrId(blockNameOrId);

            FixSelections();

            int width  = (end.x - start.x) + 1;
            int height = (end.y - start.y) + 1;
            int depth  = (end.z - start.z) + 1;

            Prefab tempPrefab = new Prefab(new Vector3i(width, height, depth));

            Log.Out("SETTING BLOCK FOR FILL:" + bv.ToItemValue().type.ToString());
            Log.Out(tempPrefab.size.ToString());
            for (var x = 0; x < tempPrefab.size.x; x++)
            {
                for (var y = 0; y < tempPrefab.size.y; y++)
                {
                    for (var z = 0; z < tempPrefab.size.z; z++)
                    {
                        tempPrefab.SetBlock(x, y, z, bv);
                    }
                }
            }

            this.selectionPrefab = tempPrefab;
            return(PasteSelection(new Vector3i(start.x, start.y, start.z)));
        }
예제 #5
0
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx,
                                          Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        if (_blockValue.ischild)
        {
            Vector3i   parentPos = Block.list[_blockValue.type].multiBlockPos.GetParentPos(_blockPos, _blockValue);
            BlockValue block     = _world.GetBlock(parentPos);
            return(this.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, parentPos, block, _player));
        }
        TileEntitySign tileEntitySign = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySign;

        if (tileEntitySign == null)
        {
            return(false);
        }
        switch (_indexInBlockActivationCommands)
        {
        case 0:
            if (GameManager.Instance.IsEditMode() || !tileEntitySign.IsLocked() || tileEntitySign.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId)))
            {
                return(this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player));
            }
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked");
            return(false);

        case 1:
            tileEntitySign.SetLocked(true);
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locking");
            GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerLocked");
            return(true);

        case 2:
            tileEntitySign.SetLocked(false);
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
            GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerUnlocked");
            return(true);

        case 3:
            XUiC_KeypadWindow.Open(LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal), tileEntitySign);
            return(true);

        case 4:
            LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal);
            ItemStack     itemStack   = new ItemStack(_blockValue.ToItemValue(), 1);
            if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack))
            {
                uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
            }
            _world.SetBlockRPC(_cIdx, _blockPos, BlockValue.Air);

            return(true);

        default:
            return(false);
        }
    }
예제 #6
0
    private void EventData_Event(object obj)
    {
        World world = GameManager.Instance.World;

        var eventData = obj as TimerEventData;

        object[] objArray = (object[])eventData.Data;

        int        _clrIdx    = (int)objArray[0];
        BlockValue blockValue = (BlockValue)objArray[1];

        Vector3i   vector3i = (Vector3i)objArray[2];
        BlockValue block    = world.GetBlock(vector3i);

        EntityPlayerLocal entityPlayerLocal = objArray[3] as EntityPlayerLocal;

        if (block.damage > 0)
        {
            GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttRepairBeforePickup", string.Empty), "ui_denied");
        }
        else if (block.type != blockValue.type)
        {
            GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttBlockMissingPickup", string.Empty), "ui_denied");
        }
        else
        {
            TileEntitySecureLootContainer tileEntity = world.GetTileEntity(_clrIdx, vector3i) as TileEntitySecureLootContainer;
            if (tileEntity.IsUserAccessing())
            {
                GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttCantPickupInUse", string.Empty), "ui_denied");
            }
            else
            {
                LocalPlayerUI uiForPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
                ItemStack     itemStack   = new ItemStack(block.ToItemValue(), 1);
                if (!uiForPlayer.xui.PlayerInventory.AddItem(itemStack, true))
                {
                    uiForPlayer.xui.PlayerInventory.DropItem(itemStack);
                }
                world.SetBlockRPC(_clrIdx, vector3i, BlockValue.Air);
            }
        }
    }
예제 #7
0
        public static string GetBlockName(BlockValue blockValue)
        {
            ItemValue itemValue = blockValue.ToItemValue();

            if (itemValue == null)
            {
                return("air");
            }

            if (itemValue.type == 0)
            {
                return("air");
            }

            ItemClass itemClass = ItemClass.list [itemValue.type];

            if (itemClass == null)
            {
                return("air");
            }

            return(itemClass.GetItemName());
        }
예제 #8
0
    // Adaptation of GameUtils.HarvestOnAttack()
    public void HarvestOnDestroy(Block _block, BlockValue _blockValue, float destructionHarvestBonus, ItemValue miningTool)
    {
        /*ItemActionMelee iat = new ItemActionMelee();
         * iat.item = miningTool.ItemClass;
         * iat.ReadFrom(miningTool.ItemClass.Properties);
         * Dictionary<string, ItemActionAttack.Bonuses> ToolBonuses = iat.ToolBonuses;*/

        if (_block != null && _block.itemsToDrop != null)
        {
            if (!_block.itemsToDrop.ContainsKey(EnumDropEvent.Destroy))
            {
                if (_blockValue.type != 0)
                {
                    ItemValue itemValue = _blockValue.ToItemValue();
                    string    itemName  = ItemClass.list[itemValue.type].GetItemName();
                    AddHarvestItemToInventory(itemValue, 1, 1f, itemName);
                }
            }
            else
            {
                List <Block.SItemDropProb> list = _block.itemsToDrop[EnumDropEvent.Destroy];
                for (int i = 0; i < list.Count; i++)
                {
                    /*float num = 1f;
                     * if (list[i].toolCategory != null)
                     * {
                     *  num = 0f;
                     *  if (ToolBonuses != null && ToolBonuses.ContainsKey(list[i].toolCategory))
                     *  {
                     *      num = ToolBonuses[list[i].toolCategory].Tool;
                     *  }
                     * }*/

                    ItemValue itemValue2 = (!list[i].name.Equals("*")) ? new ItemValue(ItemClass.GetItem(list[i].name, false).type, false) : _blockValue.ToItemValue();
                    if (itemValue2.type != 0 && ItemClass.list[itemValue2.type] != null && (list[i].prob > 0.999f || UnityEngine.Random.value <= list[i].prob))
                    {
                        //DebugMsg("Mining Tool = " + miningTool.ItemClass.Name + "\n\tDestroy ToolBonuses = " + num.ToString("0.000") + " (" + ItemClass.list[itemValue2.type].GetItemName() + ")");

                        int num2 = Mathf.RoundToInt((float)UnityEngine.Random.Range(list[i].minCount, list[i].maxCount + 1) * destructionHarvestBonus);
                        //int num2 = (int)((float)UnityEngine.Random.Range(list[i].minCount, list[i].maxCount + 1) * num);
                        if (num2 > 0)
                        {
                            AddHarvestItemToInventory(itemValue2, num2, 1f, ItemClass.list[itemValue2.type].GetItemName());
                        }
                    }
                }
            }
            if (_block.itemsToDrop.ContainsKey(EnumDropEvent.Harvest))
            {
                List <Block.SItemDropProb> list2 = _block.itemsToDrop[EnumDropEvent.Harvest];
                //string msg = "Destroying " + _block.GetBlockName() + ":\n";
                for (int k = 0; k < list2.Count; k++)
                {
                    /*float num3 = 1f;
                     * if (list2[k].toolCategory != null)
                     * {
                     *  num3 = 0f;
                     *  if (ToolBonuses != null && ToolBonuses.ContainsKey(list2[k].toolCategory))
                     *  {
                     *      num3 = ToolBonuses[list2[k].toolCategory].Tool;
                     *  }
                     * }*/
                    // Simulate the multiple harvesting hits of regular harvesting tools

                    /*float blockDamage = _block.MaxDamage;
                     * ItemActionAttack iat = new ItemActionMelee();
                     * ItemValue dummy = null;
                     * float miningToolBlockDamage = iat.GetDamageBlock(miningTool, player, dummy);*/
                    //msg += ("\tTool Block Damage = " + miningToolBlockDamage.ToString() + ":\n");
                    //for (int l = 0; blockDamage > 0 && l < 20; l++)
                    {
                        //msg += ("\tBlock Damage = " + blockDamage.ToString() + ":\n");
                        //blockDamage -= miningToolBlockDamage;

                        ItemValue itemValue3 = (!list2[k].name.Equals("*")) ? new ItemValue(ItemClass.GetItem(list2[k].name, false).type, false) : _blockValue.ToItemValue();
                        if (itemValue3.type != 0 && ItemClass.list[itemValue3.type] != null)
                        {
                            //DebugMsg("\tHarvest ToolBonuses = " + num3.ToString("0.000") + " (" + ItemClass.list[itemValue3.type].GetItemName() + ")");

                            float num3 = destructionHarvestBonus;
                            entityVehicle.player.Skills.ModifyValue(Skill.Effects.HarvestCount, ref num3, miningTool.type, false);

                            int num4 = Mathf.RoundToInt((float)UnityEngine.Random.Range(list2[k].minCount, list2[k].maxCount + 1) * num3);
                            if (num4 > 0)
                            {
                                AddHarvestItemToInventory(itemValue3, num4, list2[k].prob, ItemClass.list[itemValue3.type].GetItemName());
                            }
                        }
                    }
                    // High hit on performance
                    //DebugMsg(msg);
                }
            }
            return;
        }
    }