예제 #1
0
    // This will check if the food item actually exists in the container, before making the trip to it.
    public static ItemValue CheckContents(TileEntityLootContainer tileLootContainer, List <String> lstContents, String strSearchType)
    {
        DisplayLog(" Check Contents of Container: " + tileLootContainer.ToString());
        DisplayLog(" TileEntity: " + tileLootContainer.items.Length);
        ItemValue myItem = null;

        if (tileLootContainer.items != null)
        {
            ItemStack[] array = tileLootContainer.GetItems();
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].IsEmpty())
                {
                    continue;
                }

                DisplayLog(" Not Empty: " + array[i].itemValue.ItemClass.Name);
                // The animals will only eat the food they like best.
                if (lstContents.Contains(array[i].itemValue.ItemClass.Name))
                {
                    if (IsConsumable(array[i].itemValue, strSearchType) != null)
                    {
                        myItem = array[i].itemValue;
                    }
                }
                else if (lstContents.Count == 0)
                {
                    DisplayLog(" No Filtered list. Checking if its edible.");
                    if (IsConsumable(array[i].itemValue, strSearchType) != null)
                    {
                        myItem = array[i].itemValue;
                    }
                }

                if (myItem != null)
                {
                    if (IsConsumable(myItem, strSearchType) != null)
                    {
                        DisplayLog(" My Item is consumable: " + myItem.ItemClass.GetItemName());
                        // if there's only one left, remove the entire item; otherwise, decrease it.
                        if (array[i].count == 1)
                        {
                            tileLootContainer.RemoveItem(array[i].itemValue);
                        }
                        else
                        {
                            array[i].count--;
                        }

                        tileLootContainer.UpdateSlot(i, array[i]);

                        return(myItem);
                    }
                }
            }
        }

        DisplayLog("CheckContents(): No Items found.");
        return(null);
    }
예제 #2
0
    // We want to set down the file if it doesn't already exist, but we don't want to do the Loot container check
    // We want it to only have a 1,1 slot, but don't want to waste a loot container id for it.
    public override void OnBlockAdded(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
    {
        #region OnBlockAdded
        if (_blockValue.ischild)
        {
            return;
        }
        this.shape.OnBlockAdded(world, _chunk, _blockPos, _blockValue);
        if (this.isMultiBlock)
        {
            this.multiBlockPos.AddChilds(world, _chunk.ClrIdx, _blockPos, _blockValue);
        }

        if (!(world.GetTileEntity(_chunk.ClrIdx, _blockPos) is TileEntitySecureLootContainer))
        {
            TileEntityLootContainer tileEntityLootContainer = new TileEntityLootContainer(_chunk);
            tileEntityLootContainer.localChunkPos = World.toBlock(_blockPos);
            tileEntityLootContainer.lootListIndex = 25;
            tileEntityLootContainer.SetContainerSize(vLootContainerSize, true);
            _chunk.AddTileEntity(tileEntityLootContainer);
        }

        _chunk.AddEntityBlockStub(new BlockEntityData(_blockValue, _blockPos)
        {
            bNeedsTemperature = true
        });

        #endregion
    }
        private void SetHistory(TileEntityLootContainer lc)
        {
            if (lc != null)
            {
                lastTouched = lc.worldTimeTouched;
                //lastOpened = lc.GetOpenTime();

                if (lc.items != null)
                {
                    items = new KeyValuePair <ItemValue, int> [lc.items.Length];
                    ItemStack[] itemList = lc.GetItems();
                    if (itemList != null)
                    {
                        for (int i = 0; i < itemList.Length; i++)
                        {
                            ItemStack item = (ItemStack)itemList[i];
                            if (item != null)
                            {
                                if (item.itemValue != null)
                                {
                                    ItemValue iv        = item.itemValue.Clone();
                                    int       itemCount = item.count;
                                    KeyValuePair <ItemValue, int> kvp = new KeyValuePair <ItemValue, int> (iv, itemCount);
                                    items [i] = kvp;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
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
    }
 public static bool IsAllowed(int _entityIdThatOpenedIt, TileEntityLootContainer lootContainer)
 {
     if (Backpacks.ContainsKey(lootContainer.entityId))
     {
         Backpacks.TryGetValue(lootContainer.entityId, out int ownerId);
         if (_entityIdThatOpenedIt == ownerId)
         {
             Backpacks.Remove(lootContainer.entityId);
             PersistentContainer.Instance.Backpacks.Remove(lootContainer.entityId);
             PersistentContainer.DataChange = true;
             return(true);
         }
         else if (Friend_Access)
         {
             PersistentPlayerData ppdAccess = PersistentOperations.GetPersistentPlayerDataFromEntityId(_entityIdThatOpenedIt);
             PersistentPlayerData ppdOwner  = PersistentOperations.GetPersistentPlayerDataFromEntityId(ownerId);
             if (ppdAccess != null && ppdOwner != null)
             {
                 if (ppdAccess.ACL.Contains(ppdAccess.UserIdentifier) && ppdOwner.ACL.Contains(ppdOwner.UserIdentifier))
                 {
                     Backpacks.Remove(lootContainer.entityId);
                     PersistentContainer.Instance.Backpacks.Remove(lootContainer.entityId);
                     PersistentContainer.DataChange = true;
                     return(true);
                 }
             }
         }
         return(false);
     }
     return(true);
 }
예제 #6
0
    public override void PostInit()
    {
        base.PostInit();

        // disable god mode, since that's enabled by default in the NPC
        IsGodMode.Value = false;

        if (NPCInfo != null)
        {
            DefaultTraderID = NPCInfo.TraderID;
        }

        InvokeRepeating("DisplayStats", 0f, 60f);

        // Check if there's a loot container or not already attached to store its stuff.
        DisplayLog(" Checking Entity's Loot Container");
        if (lootContainer == null)
        {
            DisplayLog(" Entity does not have a loot container. Creating one.");
            int lootList = GetLootList();
            DisplayLog(" Loot list is: " + lootList);
            lootContainer          = new TileEntityLootContainer(null);
            lootContainer.entityId = entityId;
            lootContainer.SetContainerSize(new Vector2i(8, 6), true);

            // If the loot list is available, set the container to that size.
            if (lootList != 0)
            {
                lootContainer.SetContainerSize(LootContainer.lootList[lootList].size, true);
            }
        }

        Buffs.SetCustomVar("$waterStaminaRegenAmount", 0, false);
    }
예제 #7
0
    public void ScanForTileEntityInList()
    {
        DisplayLog("ScanForTileEntityInList()");
        this.lstTileContainers.Clear();
        Vector3i blockPosition = this.theEntity.GetBlockPosition();

        var minX = prefab.boundingBoxPosition.x;
        var maxX = prefab.boundingBoxPosition.x + prefab.boundingBoxSize.x - 1;

        var minZ = prefab.boundingBoxPosition.z;
        var maxZ = prefab.boundingBoxPosition.z + prefab.boundingBoxSize.z - 1;

        int num  = World.toChunkXZ(blockPosition.x);
        int num2 = World.toChunkXZ(blockPosition.z);

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                Chunk chunk = (Chunk)theEntity.world.GetChunkSync(num + j, num2 + i);
                if (chunk != null)
                {
                    var chunkPos = chunk.GetWorldPos();
                    var worldX   = chunkPos.x + i;
                    var worldZ   = chunkPos.z + j;

                    // Out of bounds
                    if (worldX < minX || worldX > maxX || worldZ < minZ || worldZ > maxZ)
                    {
                        continue;
                    }

                    // Grab all the Tile Entities in the chunk
                    DictionaryList <Vector3i, TileEntity> tileEntities = chunk.GetTileEntities();
                    for (int k = 0; k < tileEntities.list.Count; k++)
                    {
                        TileEntityLootContainer tileEntity = tileEntities.list[k] as TileEntityLootContainer;
                        if (tileEntity != null)
                        {
                            BlockValue block = theEntity.world.GetBlock(tileEntity.ToWorldPos());
                            if (tileEntity.bTouched)
                            {
                                DisplayLog(" This tile Entity has already been touched: " + tileEntities.ToString());
                                continue;
                            }

                            if (Block.list[block.type].HasTag(BlockTags.Door))
                            {
                                DisplayLog(" This tile entity is a door. ignoring.");
                                continue;
                            }
                            DisplayLog(" Loot Container: " + tileEntity.ToString() + " Distance: " + Vector3.Distance(tileEntity.ToWorldPos().ToVector3(), this.theEntity.position));
                            this.lstTileContainers.Add(tileEntity);
                        }
                    }
                }
            }
        }
    }
예제 #8
0
 public void NotifyLootContainerItemChangedHandlers(TileEntityLootContainer lc, int slotIdx, ItemStack oldStack, ItemStack newStack)
 {
     //Log.Out ("LOOT ITEM CHANGED" + slotIdx.ToString());
     if (OnLootContainerItemChanged != null)
     {
         OnLootContainerItemChanged(lc, slotIdx, oldStack, newStack);
     }
 }
예제 #9
0
    public bool CheckContainer()
    {
        this.theEntity.SetLookPosition(seekPos);

        Ray lookRay = new Ray(this.theEntity.position, theEntity.GetLookVector());

        if (!Voxel.Raycast(this.theEntity.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0f))
        {
            DisplayLog(" Ray cast is invalid");
            return(false); // Not seeing the target.
        }
        if (!Voxel.voxelRayHitInfo.bHitValid)
        {
            DisplayLog(" Look cast is not valid.");
            return(false); // Missed the target. Overlooking?
        }
        //    float sqrMagnitude2 = (this.seekPos - this.theEntity.position).sqrMagnitude;
        //if (sqrMagnitude2 > 1f)
        //{
        //    return false; // too far away from it
        //}
        DisplayLog(" Looking at: " + this.seekPos + " My position is: " + this.theEntity.position);
        TileEntityLootContainer tileEntityLootContainer = this.theEntity.world.GetTileEntity(Voxel.voxelRayHitInfo.hit.clrIdx, new Vector3i(seekPos)) as TileEntityLootContainer;

        if (tileEntityLootContainer == null)
        {
            DisplayLog("No Loot container here.");
            return(false);
        }


        //Debug.Log(" Starting: " + "IsLooting");
        //this.theEntity.emodel.avatarController.SetBool("IsLooting", true);
        //CoroutineJobTasks job = new CoroutineJobTasks();
        //job.Start();
        //Debug.Log(" Ending " + "IsLooting");
        //this.theEntity.emodel.avatarController.SetBool("IsLooting", false);


        //job.ConfigureRoutine(this.theEntity, "IsLooting", 5f);
        //job.StartCoroutine("Start");

        GetItemFromContainer(tileEntityLootContainer);
        if (tileEntityLootContainer.IsEmpty())
        {
            DisplayLog(" Looted Container.");
            return(true);
        }
        else
        {
            DisplayLog("Did not loot the container.");
        }


        return(false);
    }
예제 #10
0
    // Grab a single item from the storage box, and remmove it.
    public ItemValue GetItemFromContainer(TileEntityLootContainer tileLootContainer, List <String> lstContents, String strSearchType)
    {
        ItemValue item = CheckContents(tileLootContainer, lstContents, strSearchType);

        if (item != null)
        {
            DisplayLog("GetItemFromContainer() Searching for item: " + item.ItemClass.Name);
            if (tileLootContainer.items != null)
            {
                ItemStack[] array = tileLootContainer.items;
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].IsEmpty()) // nothing in the slot
                    {
                        continue;
                    }

                    // The animals will only eat the food they like best.
                    if (array[i].itemValue.ItemClass.Name == item.ItemClass.Name)
                    {
                        DisplayLog(" Found item to remove.");
                        // if there's only one left, remove the entire item; otherwise, decrease it.
                        if (array[i].count == 1)
                        {
                            tileLootContainer.RemoveItem(array[i].itemValue);
                        }
                        else
                        {
                            array[i].count--;
                        }

                        tileLootContainer.UpdateSlot(i, array[i]);
                        return(array[i].itemValue);
                    }

                    // If there's no specific food items specified, then check for all water / food sources that the player can use.
                    if (lstContents.Count == 0)
                    {
                        if (IsConsumable(array[i].itemValue, strSearchType) != null)
                        {
                            return(array[i].itemValue);
                        }
                    }
                }
            }
        }
        return(null);
    }
예제 #11
0
        public BCMTileEntityLootContainer(Vector3i pos, [NotNull] TileEntityLootContainer te) : base(pos, te)
        {
            LootList    = te.lootListIndex;
            Touched     = te.bWasTouched;
            TimeTouched = te.worldTimeTouched;
            Size        = new BCMVector2(te.GetContainerSize());
            OpenTime    = te.GetOpenTime();

            foreach (var itemStack in te.GetItems())
            {
                if (itemStack.itemValue.type == 0)
                {
                    continue;
                }

                Items.Add(new BCMItemStack(itemStack));
            }
        }
        public void OnTileEntityChanged(TileEntity _te, int _dataObject)
        {
            if (_te == null)
            {
                return;
            }
            if (_te is TileEntityLootContainer)
            {
                TileEntityLootContainer lc = _te as TileEntityLootContainer;

                bool isChanged = false;

                /*if (lc.worldTimeTouched != lastTouched) {
                 *      SDTM.API.Events.NotifyLootContainerTouchedChangedHandlers (lc, lastTouched, lc.worldTimeTouched);
                 *      isChanged = true;
                 * }*/

//				if (lastOpened != lc.GetOpenTime ()) {
//					SDTM.API.Events.NotifyLootContainerOpenedTimeChangedHandlers (lc, lastOpened, lc.GetOpenTime ());
//					isChanged = true;
//				}

                ItemStack[] itemList = lc.GetItems();
                for (int i = 0; i < itemList.Length; i++)
                {
                    ItemStack item = (ItemStack)itemList.GetValue(i);
                    ItemValue iv   = item.itemValue.Clone();

                    if (iv.type != items [i].Key.type || item.count != items[i].Value)
                    {
                        ItemStack oldStack = new ItemStack(items [i].Key, items [i].Value);
                        SDTM.API.Events.NotifyLootContainerItemChangedHandlers(lc, i, oldStack, item);
                        isChanged = true;
                    }
                }

                if (isChanged)
                {
                    SetHistory(lc);
                }
            }
        }
예제 #13
0
 public static void lootContainerOpened(TileEntityLootContainer _te, LocalPlayerUI _playerUI, int _entityIdThatOpenedIt)
 {
     if (_playerUI != null)
     {
         bool   flag = true;
         string lootContainerName = string.Empty;
         if (_te.entityId != -1)
         {
             Entity entity = GameManager.Instance.World.GetEntity(_te.entityId);
             if (entity != null)
             {
                 lootContainerName = Localization.Get(EntityClass.list[entity.entityClass].entityClassName, "");
                 if (entity is EntityVehicle)
                 {
                     flag = false;
                 }
             }
         }
         else
         {
             BlockValue block = GameManager.Instance.World.GetBlock(_te.ToWorldPos());
             lootContainerName = Localization.Get(Block.list[block.type].GetBlockName(), "");
         }
         if (flag)
         {
             ((XUiC_LootWindowGroup)((XUiWindowGroup)_playerUI.windowManager.GetWindow("looting")).Controller).SetTileEntityChest(lootContainerName, _te);
             _playerUI.windowManager.Open("looting", true, false, true);
         }
         LootContainer lootContainer = LootContainer.lootList[_te.lootListIndex];
         if (lootContainer != null && _playerUI.entityPlayer != null)
         {
             lootContainer.ExecuteBuffActions(_te.entityId, _playerUI.entityPlayer);
         }
     }
     if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer)
     {
         GameManager.Instance.lootManager.LootContainerOpened(_te, _entityIdThatOpenedIt);
         _te.bTouched = true;
         _te.SetModified();
     }
 }
예제 #14
0
    public override void PostInit()
    {
        base.PostInit();

        // disable god mode, since that's enabled by default in the NPC
        IsGodMode.Value = false;

        if (NPCInfo != null)
        {
            DefaultTraderID = NPCInfo.TraderID;
        }

        InvokeRepeating("DisplayStats", 0f, 60f);

        // Check if there's a loot container or not already attached to store its stuff.
        DisplayLog(" Checking Entity's Loot Container");
        if (lootContainer == null)
        {
            DisplayLog(" Entity does not have a loot container. Creating one.");
            int lootList = GetLootList();
            DisplayLog(" Loot list is: " + lootList);
            lootContainer          = new TileEntityLootContainer(null);
            lootContainer.entityId = entityId;
            lootContainer.SetContainerSize(new Vector2i(8, 6), true);

            // If the loot list is available, set the container to that size.
            if (lootList != 0)
            {
                lootContainer.SetContainerSize(LootContainer.lootList[lootList].size, true);
            }
        }

        Buffs.SetCustomVar("$waterStaminaRegenAmount", 0, false);

        SetupStartingItems();
        inventory.SetHoldingItemIdx(0);

        // Does a quick local scan to see what pathing blocks, if any, are nearby. If one is found nearby, then it'll use that code for pathing.
        SetupAutoPathingBlocks();
    }
예제 #15
0
    // This will check if the food item actually exists in the container, before making the trip to it.
    public ItemValue CheckContents(TileEntityLootContainer tileLootContainer, List <String> lstContents, String strSearchType)
    {
        DisplayLog(" Check Contents of Container: " + tileLootContainer.ToString());
        DisplayLog(" TileEntity: " + tileLootContainer.items.Length);

        if (tileLootContainer.items != null)
        {
            ItemStack[] array = tileLootContainer.GetItems();
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].IsEmpty())
                {
                    //DisplayLog(" Empty Slot");
                    continue;
                }
                DisplayLog(" Not Empty: " + array[i].itemValue.ItemClass.Name);
                // The animals will only eat the food they like best.
                if (lstContents.Contains(array[i].itemValue.ItemClass.Name))
                {
                    DisplayLog(" Found food item: " + array[i].itemValue.ItemClass.Name);
                    return(array[i].itemValue);
                }

                DisplayLog(" Contents Count: " + lstContents.Count);
                // If there's no items to compare again, such as food items or water items, then do a action check if its food.
                if (lstContents.Count == 0)
                {
                    DisplayLog(" No Filtered list. Checking if its edible.");
                    if (IsConsumable(array[i].itemValue, strSearchType) != null)
                    {
                        return(array[i].itemValue);
                    }
                }
            }
        }

        return(null);
    }
예제 #16
0
    public static bool CheckForBin(int EntityID, String StatType)
    {
        EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX;

        if (!myEntity)
        {
            return(false);
        }


        DisplayLog(myEntity.entityId + " CheckForBin() " + StatType);
        // There is too many values that we need to read in from the entity, so we'll read them directly from the entityclass
        EntityClass entityClass = EntityClass.list[myEntity.entityClass];

        List <String> lstContainers = new List <String>();
        List <String> lstItems      = new List <String>();

        switch (StatType)
        {
        case "Food":
            // If it isn't hungry, don't look for food.
            if (!EntityUtilities.isEntityHungry(EntityID))
            {
                return(false);
            }

            lstContainers = ConfigureEntityClass("FoodBins", entityClass);
            lstItems      = ConfigureEntityClass("FoodItems", entityClass);
            break;

        case "Water":

            if (!EntityUtilities.isEntityThirsty(EntityID))
            {
                return(false);
            }

            lstContainers = ConfigureEntityClass("WaterBins", entityClass);
            lstItems      = ConfigureEntityClass("WaterItems", entityClass);
            break;

        case "Health":
            if (!EntityUtilities.isEntityHurt(EntityID))
            {
                return(false);
            }

            DisplayLog("CheckForBin(): Health Items not implemented");
            return(false);

        default:
            DisplayLog("CheckForBin(): Default is not implemented");
            return(false);
        }
        ;

        // Checks the Entity's backpack to see if it can meet its needs there.
        ItemValue item   = CheckContents(myEntity.lootContainer, lstItems, StatType);
        bool      result = ConsumeProduct(EntityID, item);

        if (result)
        {
            DisplayLog("CheckForBin(): Found Item in my Back pack: " + item.ItemClass.GetItemName());
            return(false);  // If we found something to consume, don't bother looking further.
        }
        // If the entity already has an investigative position, check to see if we are close enough for it.
        if (myEntity.HasInvestigatePosition)
        {
            DisplayLog(" CheckForBin(): Has Investigative position. Checking distance to bin");
            float sqrMagnitude2 = (myEntity.InvestigatePosition - myEntity.position).sqrMagnitude;
            if (sqrMagnitude2 <= 4f)
            {
                DisplayLog(" CheckForBin(): I am close to a bin.");
                Vector3i   blockLocation = new Vector3i(myEntity.InvestigatePosition.x, myEntity.InvestigatePosition.y, myEntity.InvestigatePosition.z);
                BlockValue checkBlock    = myEntity.world.GetBlock(blockLocation);
                DisplayLog(" CheckForBin(): Target Block is: " + checkBlock);
                TileEntityLootContainer myTile = myEntity.world.GetTileEntity(0, blockLocation) as TileEntityLootContainer;
                if (myTile != null)
                {
                    item = CheckContents(myTile, lstItems, StatType);
                    if (item != null)
                    {
                        DisplayLog("CheckForBin() I retrieved: " + item.ItemClass.GetItemName());
                    }
                    result = ConsumeProduct(EntityID, item);
                    DisplayLog(" Did I consume? " + result);
                    return(result);
                }
            }
            return(false);
        }

        DisplayLog(" Scanning For " + StatType);
        Vector3 TargetBlock = ScanForBlockInList(myEntity.position, lstContainers, Utils.Fastfloor(myEntity.GetSeeDistance()));

        if (TargetBlock == Vector3.zero)
        {
            return(false);
        }

        DisplayLog(" Setting Target:" + GameManager.Instance.World.GetBlock(new Vector3i(TargetBlock)).Block.GetBlockName());
        myEntity.SetInvestigatePosition(TargetBlock, 120);
        return(true);
    }
예제 #17
0
 private static void Penalty(ClientInfo _cInfo)
 {
     try
     {
         PlayerDataFile _pdf = PersistentOperations.GetPlayerDataFileFromSteamId(_cInfo.playerId);
         if (_pdf != null)
         {
             Vector3i _pos = new Vector3i((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z);
             if (GameManager.Instance.World.IsChunkAreaLoaded(_pos.x, _pos.y, _pos.z))
             {
                 Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos(_pos.x, _pos.y, _pos.z);
                 if (chunk != null)
                 {
                     BlockValue _blockValue = Block.GetBlockValue("cntStorageChest");
                     if (_blockValue.Block != null)
                     {
                         GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, _blockValue);
                         TileEntityLootContainer tileEntityLootContainer = GameManager.Instance.World.GetTileEntity(chunk.ClrIdx, _pos) as TileEntityLootContainer;
                         if (tileEntityLootContainer != null)
                         {
                             if (All || Bag)
                             {
                                 for (int i = 0; i < _pdf.bag.Length; i++)
                                 {
                                     if (!_pdf.bag[i].IsEmpty())
                                     {
                                         tileEntityLootContainer.AddItem(_pdf.bag[i]);
                                         _pdf.bag[i] = ItemStack.Empty.Clone();
                                     }
                                 }
                             }
                             if (All || Belt)
                             {
                                 for (int i = 0; i < _pdf.inventory.Length; i++)
                                 {
                                     if (!_pdf.inventory[i].IsEmpty())
                                     {
                                         tileEntityLootContainer.AddItem(_pdf.inventory[i]);
                                         _pdf.inventory[i] = ItemStack.Empty.Clone();
                                     }
                                 }
                             }
                             if (All || Equipment)
                             {
                                 ItemValue[] _equipmentValues = _pdf.equipment.GetItems();
                                 for (int i = 0; i < _equipmentValues.Length; i++)
                                 {
                                     if (!_equipmentValues[i].IsEmpty())
                                     {
                                         ItemStack _itemStack = new ItemStack(_equipmentValues[i], 1);
                                         tileEntityLootContainer.AddItem(_itemStack);
                                         _equipmentValues[i].Clear();
                                     }
                                 }
                             }
                             if (tileEntityLootContainer.IsEmpty())
                             {
                                 GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, BlockValue.Air);
                             }
                             else
                             {
                                 tileEntityLootContainer.SetModified();
                             }
                             PersistentOperations.SavePlayerDataFile(_cInfo.playerId, _pdf);
                         }
                     }
                 }
             }
             else
             {
                 ChunkManager.ChunkObserver _observer = GameManager.Instance.AddChunkObserver(_pos.ToVector3(), false, 2, -1);
                 if (_observer != null)
                 {
                     Thread.Sleep(1000);
                     Chunk _chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos(_pos.x, _pos.y, _pos.z);
                     if (_chunk != null)
                     {
                         EntityBackpack entityBackpack = new EntityBackpack();
                         entityBackpack               = EntityFactory.CreateEntity("Backpack".GetHashCode(), _pdf.ecd.pos + Vector3.up * 2f) as EntityBackpack;
                         entityBackpack.RefPlayerId   = _pdf.ecd.clientEntityId;
                         entityBackpack.lootContainer = new TileEntityLootContainer(null);
                         entityBackpack.lootContainer.SetUserAccessing(true);
                         entityBackpack.lootContainer.SetEmpty();
                         entityBackpack.lootContainer.lootListIndex = entityBackpack.GetLootList();
                         entityBackpack.lootContainer.SetContainerSize(LootContainer.lootList[entityBackpack.GetLootList()].size, true);
                         if (All || Bag)
                         {
                             for (int i = 0; i < _pdf.bag.Length; i++)
                             {
                                 if (!_pdf.bag[i].IsEmpty())
                                 {
                                     entityBackpack.lootContainer.AddItem(_pdf.bag[i]);
                                     _pdf.bag[i] = ItemStack.Empty.Clone();
                                 }
                             }
                         }
                         if (All || Belt)
                         {
                             for (int i = 0; i < _pdf.inventory.Length; i++)
                             {
                                 if (!_pdf.inventory[i].IsEmpty())
                                 {
                                     entityBackpack.lootContainer.AddItem(_pdf.inventory[i]);
                                     _pdf.inventory[i] = ItemStack.Empty.Clone();
                                 }
                             }
                         }
                         if (All || Equipment)
                         {
                             ItemValue[] _equipmentValues = _pdf.equipment.GetItems();
                             for (int i = 0; i < _equipmentValues.Length; i++)
                             {
                                 if (!_equipmentValues[i].IsEmpty())
                                 {
                                     ItemStack _itemStack = new ItemStack(_equipmentValues[i], 1);
                                     entityBackpack.lootContainer.AddItem(_itemStack);
                                     _equipmentValues[i].Clear();
                                 }
                             }
                         }
                         _pdf.droppedBackpackPosition = new Vector3i(_pdf.ecd.pos);
                         entityBackpack.lootContainer.bPlayerBackpack = true;
                         entityBackpack.lootContainer.SetUserAccessing(false);
                         entityBackpack.lootContainer.SetModified();
                         entityBackpack.entityId    = -1;
                         entityBackpack.RefPlayerId = _pdf.ecd.clientEntityId;
                         EntityCreationData entityCreationData = new EntityCreationData(entityBackpack);
                         entityCreationData.entityName    = string.Format(Localization.Get("playersBackpack"), _pdf.ecd.entityName);
                         entityCreationData.id            = -1;
                         entityCreationData.lootContainer = entityBackpack.lootContainer.Clone();
                         PersistentOperations.SavePlayerDataFile(_cInfo.playerId, _pdf);
                         GameManager.Instance.RequestToSpawnEntityServer(entityCreationData);
                         entityBackpack.OnEntityUnload();
                     }
                     GameManager.Instance.RemoveChunkObserver(_observer);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ExitCommand.Penalty: {0}", e.Message));
     }
 }
예제 #18
0
    // Grab a single item from the storage box, and remmove it.
    public void GetItemFromContainer(TileEntityLootContainer tileLootContainer)
    {
        Ray lookRay = new Ray(this.theEntity.position, theEntity.GetLookVector());
        if (!Voxel.Raycast(this.theEntity.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0f))
            return;  // Not seeing the target.

        if (!Voxel.voxelRayHitInfo.bHitValid)
            return; // Missed the target. Overlooking?

        Vector3i blockPos = tileLootContainer.ToWorldPos();
        this.lstTileContainers.Remove(tileLootContainer);

        DisplayLog(" Loot List: " + tileLootContainer.lootListIndex);
        if (tileLootContainer.lootListIndex <= 0)
            return;
        if (tileLootContainer.bTouched)
            return;

        tileLootContainer.bTouched = true;
        tileLootContainer.bWasTouched = true;

        DisplayLog("Checking Loot Container");
        if (tileLootContainer.items != null)
        {
            BlockValue block = this.theEntity.world.GetBlock(blockPos);
            String lootContainerName = Localization.Get(Block.list[block.type].GetBlockName(), string.Empty);
            theEntity.SetLookPosition(blockPos.ToVector3());

            DisplayLog(" Loot container is: " + lootContainerName);
            DisplayLog(" Loot Container has this many Slots: " + tileLootContainer.items.Length);

            EntityPlayer player = null;
            if (this.theEntity.Buffs.HasCustomVar("Leader"))
                player = theEntity.world.GetEntity((int)this.theEntity.Buffs.GetCustomVar("Leader")) as EntityPlayerLocal;

            theEntity.MinEventContext.TileEntity = tileLootContainer;
            theEntity.FireEvent(MinEventTypes.onSelfOpenLootContainer);
            UnityEngine.Random.State state = UnityEngine.Random.state;
            UnityEngine.Random.InitState((int)(GameManager.Instance.World.worldTime % 2147483647UL));
            ItemStack[] array = LootContainer.lootList[tileLootContainer.lootListIndex].Spawn(tileLootContainer.items.Length, EffectManager.GetValue(PassiveEffects.LootGamestage, null, (float)player.PartyGameStage, player, null, default(FastTags), true, true, true, true), 0f);
            UnityEngine.Random.state = state;
            for (int i = 0; i < array.Length; i++)
            {
                if (this.theEntity.lootContainer.AddItem(array[i].Clone()))
                {
                    DisplayLog("Removing item from loot container: " + array[i].itemValue.ItemClass.Name);
                }
                else
                {
                    DisplayLog(" Could Not add Item to NPC inventory. " + tileLootContainer.items[i].itemValue.ToString());
                    if (theEntity is EntityAliveSDX)
                    {
                        (theEntity as EntityAliveSDX).ExecuteCMD("Follow", player);
                        return;
                    }

                }

            }
            theEntity.FireEvent(MinEventTypes.onSelfLootContainer);

        }

    }
예제 #19
0
    public virtual Vector3 ScanForTileEntityInList(List <String> lstBlocks, List <String> lstContents)
    {
        // If there's no blocks to look for, don't do anything.
        if (lstBlocks.Count == 0)
        {
            return(Vector3.zero);
        }

        DisplayLog("Scanning For Tile Entities: " + string.Join(", ", lstBlocks.ToArray()));
        DisplayLog(" Contents: " + string.Join(", ", lstContents.ToArray()));
        List <Vector3> localLists = new List <Vector3>();


        // Otherwise, search for your new home.
        Vector3i blockPosition = this.theEntity.GetBlockPosition();
        int      num           = World.toChunkXZ(blockPosition.x);
        int      num2          = World.toChunkXZ(blockPosition.z);

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                Chunk chunk = (Chunk)theEntity.world.GetChunkSync(num + j, num2 + i);
                if (chunk != null)
                {
                    // Grab all the Tile Entities in the chunk
                    DictionaryList <Vector3i, TileEntity> tileEntities = chunk.GetTileEntities();
                    for (int k = 0; k < tileEntities.list.Count; k++)
                    {
                        TileEntityLootContainer tileEntity = tileEntities.list[k] as TileEntityLootContainer;
                        if (tileEntity != null)
                        {
                            BlockValue block = theEntity.world.GetBlock(tileEntity.ToWorldPos());
                            DisplayLog(" Found Block: " + block.Block.GetBlockName());
                            // if its not a listed block, then keep searching.
                            if (!lstBlocks.Contains(block.Block.GetBlockName()))
                            {
                                continue;
                            }

                            DisplayLog(" Tile Entity is in my Filtered list: " + block.Block.GetBlockName());
                            if (lstContents.Count > 0)
                            {
                                DisplayLog(" My Content List is Empty. Searcing for regular food items.");
                                if (CheckContents(tileEntity, lstContents, "Food") != null)
                                {
                                    DisplayLog(" Box has food contents: " + tileEntities.ToString());
                                    localLists.Add(tileEntity.ToWorldPos().ToVector3());
                                }
                                else
                                {
                                    DisplayLog(" Empty Container: " + tileEntities.ToString());
                                }
                            }
                            else
                            {
                                localLists.Add(tileEntity.ToWorldPos().ToVector3());
                            }
                        }
                    }
                }
            }
        }

        // DisplayLog(" Local List: " + string.Join(", ", localLists.ToArray()));

        // Finds the closet block we matched with.
        Vector3 tMin = new Vector3();

        tMin = Vector3.zero;
        float   minDist    = Mathf.Infinity;
        Vector3 currentPos = this.theEntity.position;

        foreach (Vector3 block in localLists)
        {
            float dist = Vector3.Distance(block, currentPos);
            if (dist < minDist)
            {
                tMin    = block;
                minDist = dist;
            }
        }

        return(tMin);
    }
예제 #20
0
    // Play the music when its activated. We stop the sound broadcasting, in case they want to restart it again; otherwise we can get two sounds playing.
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        #region OnBlockActivated

        // If there's no transform, no sense on keeping going for this class.
        BlockEntityData _ebcd = _world.GetChunkFromWorldPos(_blockPos).GetBlockEntity(_blockPos);
        if (_ebcd == null || _ebcd.transform == null)
        {
            return(false);
        }

        MusicBoxScript myMusicBoxScript = _ebcd.transform.GetComponent <MusicBoxScript>();
        if (myMusicBoxScript == null)
        {
            myMusicBoxScript = _ebcd.transform.gameObject.AddComponent <MusicBoxScript>();
        }

        bool bRuntimeSwitch = myMusicBoxScript.enabled;


        // Turn off the music box before we do anything with it.
        myMusicBoxScript.enabled = false;

        if (_indexInBlockActivationCommands != 0)
        {
            if (_indexInBlockActivationCommands == 1)
            {
                base.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
            }

            if (_indexInBlockActivationCommands == 2)
            {
                TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player);
            }
        }
        else
        {
            bRuntimeSwitch = !bRuntimeSwitch;

            // Check if we have an animator and set it
            myMusicBoxScript.anim = _ebcd.transform.GetComponent <Animator>();

            // Check if we have a video player as well.
            myMusicBoxScript.videoPlayer = _ebcd.transform.GetComponent <VideoPlayer>();

            myMusicBoxScript.myBlockPos = _blockPos;
            // If the switch is on, then we want to look in the loot container to find a reference to any potential items,
            // which will over-ride the default audio clip / video clip.
            if (bRuntimeSwitch)
            {
                // We'll try to support getting sounds from multiple sound data nodes, based on all the items in the loot container.
                List <String> mySounds = new List <String>();
                List <String> myVideos = new List <String>();

                TileEntityLootContainer tileLootContainer = (TileEntityLootContainer)_world.GetTileEntity(_cIdx, _blockPos);

                if (tileLootContainer.items != null)
                {
                    ItemStack[] array = tileLootContainer.items;
                    for (int i = 0; i < array.Length; i++)
                    {
                        if (array[i].IsEmpty())
                        {
                            continue;
                        }

                        // Check for a SoundDataNode for a potential sound clip.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("SoundDataNode"))
                        {
                            String strSound = array[i].itemValue.ItemClass.Properties.Values["SoundDataNode"];
                            if (!mySounds.Contains(strSound))
                            {
                                mySounds.Add(strSound);
                            }
                        }
                        // Check for a video Source for a video clip. If we find it, load the asset and add it to the music box script.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("VideoSource"))
                        {
                            // Check if the video source is an asset bundle, and if so, load it directly into the video clip on
                            String strVideo = array[i].itemValue.ItemClass.Properties.Values["VideoSource"];
                            if (strVideo.IndexOf('#') == 0 && strVideo.IndexOf('?') > 0)
                            {
                                if (!myVideos.Contains(strVideo))
                                {
                                    myVideos.Add(strVideo);
                                }
                            }
                        }
                    }
                }

                // Initialize the data with our defaults.
                myMusicBoxScript.strAudioSource = this.strAudioSource;
                myMusicBoxScript.strSoundSource = this.strSoundSource;
                myMusicBoxScript.strVideoSource = this.strVideoSource;
                myMusicBoxScript.myEntity       = _player;

                // List of Videos and Sound clips.
                myMusicBoxScript.VideoGroups = myVideos;
                myMusicBoxScript.SoundGroups = mySounds;

                myMusicBoxScript.myVideoClip = null;
                myMusicBoxScript.enabled     = bRuntimeSwitch;
            }
        }


        return(false);

        #endregion
    }
 public TELootContainerChangedHandler(TileEntityLootContainer lc)
 {
     SetHistory(lc);
 }
예제 #22
0
 private static void Penalty(PlayerDataFile _pdf, ClientInfo _cInfo)
 {
     try
     {
         Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z);
         if (chunk != null)
         {
             BlockValue _blockValue = Block.GetBlockValue("cntStorageChest");
             if (_blockValue.Block != null)
             {
                 Vector3i _pos = new Vector3i((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z);
                 GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, _blockValue);
                 TileEntityLootContainer tileEntityLootContainer = GameManager.Instance.World.GetTileEntity(chunk.ClrIdx, _pos) as TileEntityLootContainer;
                 if (tileEntityLootContainer != null)
                 {
                     if (All || Bag)
                     {
                         for (int i = 0; i < _pdf.bag.Length; i++)
                         {
                             if (!_pdf.bag[i].IsEmpty())
                             {
                                 tileEntityLootContainer.AddItem(_pdf.bag[i]);
                                 _pdf.bag[i] = ItemStack.Empty.Clone();
                             }
                         }
                     }
                     if (All || Belt)
                     {
                         for (int i = 0; i < _pdf.inventory.Length; i++)
                         {
                             if (!_pdf.inventory[i].IsEmpty())
                             {
                                 tileEntityLootContainer.AddItem(_pdf.inventory[i]);
                                 _pdf.inventory[i] = ItemStack.Empty.Clone();
                             }
                         }
                     }
                     if (All || Equipment)
                     {
                         ItemValue[] _equipmentValues = _pdf.equipment.GetItems();
                         for (int i = 0; i < _equipmentValues.Length; i++)
                         {
                             if (!_equipmentValues[i].IsEmpty())
                             {
                                 ItemStack _itemStack = new ItemStack(_equipmentValues[i], 1);
                                 tileEntityLootContainer.AddItem(_itemStack);
                                 _equipmentValues[i].Clear();
                             }
                         }
                     }
                     if (tileEntityLootContainer.IsEmpty())
                     {
                         GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, BlockValue.Air);
                     }
                     else
                     {
                         tileEntityLootContainer.SetModified();
                     }
                     PersistentOperations.SavePlayerDataFile(_cInfo.playerId, _pdf);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in BattleLogger.Penalty: {0}", e.Message));
     }
 }
예제 #23
0
    // Virtual methods to overload, so we can choose what kind of action to take.
    public virtual bool PerformAction()
    {
        DisplayLog("PerformAction() ");
        // Look at the target.

        //if (this.investigatePos != Vector3.zero)
        //{
        this.theEntity.SetLookPosition(seekPos);

        //    Ray lookRay = new Ray(this.theEntity.position, theEntity.GetLookVector());
        //    if (!Voxel.Raycast(this.theEntity.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0f))
        //        return false; // Not seeing the target.

        //    if (!Voxel.voxelRayHitInfo.bHitValid)
        //        return false; // Missed the target. Overlooking?
        //}
        DisplayLog("Before: " + this.theEntity.ToString());

        BlockValue checkBlock = theEntity.world.GetBlock(new Vector3i(seekPos.x, seekPos.y, seekPos.z));

        // Original hand item.
        ItemClass original = this.theEntity.inventory.holdingItem;

        // Look at the water, then execute the action on the empty jar.
        this.theEntity.SetLookPosition(seekPos);

        // Execute the drinking process
        if (CheckIncentive(this.lstThirstyBuffs))
        {
            DisplayLog("Thirsty Check Block: " + checkBlock.Block.GetBlockName());

            ItemValue item = null;


            // Is it a water block?
            if (checkBlock.Block.blockMaterial.IsLiquid)
            {
                // This is the actual item we want to drink out of. The above is just to deplete the water source.
                this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem("drinkJarEmpty", false));
                this.theEntity.Use(true);
                this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem(original.Name, false));

                return(true);
            }
            else if (this.lstWaterBins.Contains(checkBlock.Block.GetBlockName()))  // If the water bins are configured, then look inside for something to drink. This is for NPCs, rather than cows.
            {
                DisplayLog(" Checking water Bin: " + checkBlock.Block.GetBlockName());
                TileEntityLootContainer tileEntityLootContainer = this.theEntity.world.GetTileEntity(Voxel.voxelRayHitInfo.hit.clrIdx, new Vector3i(seekPos)) as TileEntityLootContainer;
                if (tileEntityLootContainer == null)
                {
                    return(false); // it's not a loot container.
                }
                // Check if it has any water in it.
                if (CheckContents(tileEntityLootContainer, this.lstWaterItems, "Water") != null)
                {
                    DisplayLog(" Found a water item");
                    item = GetItemFromContainer(tileEntityLootContainer, this.lstWaterItems, "Water");
                }
            }

            // Check the back pack
            else if (CheckContents(this.theEntity.lootContainer, this.lstWaterItems, "Water") != null)
            {
                DisplayLog(" Checking NPCs backpack ");
                item = GetItemFromContainer(this.theEntity.lootContainer, this.lstWaterItems, "Water");
            }

            if (item != null)
            {
                DisplayLog(" Drinking: " + item.ItemClass.GetItemName());
                // Hold the food item.
                this.theEntity.inventory.SetBareHandItem(item);
                this.theEntity.Attack(true);
                // We want to consume the food, but the consumption of food isn't supported on the non-players, so just fire off the buff
                this.theEntity.FireEvent(MinEventTypes.onSelfPrimaryActionEnd);
                this.theEntity.FireEvent(MinEventTypes.onSelfHealedSelf);

                DisplayLog(" Drinking");
                // restore the hand item.
                this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem(original.Name, false));

                return(true);
            }



            // see if the block is an entity, rather than a watering hold.
            float milkLevel = this.GetEntityWater();
            if (milkLevel > 0)
            {
                if (this.theEntity.Buffs.HasCustomVar("Mother"))
                {
                    DisplayLog("Checking For mother");
                    int            MotherID     = (int)this.theEntity.Buffs.GetCustomVar("Mother");
                    EntityAliveSDX MotherEntity = this.theEntity.world.GetEntity(MotherID) as EntityAliveSDX;
                    if (MotherEntity)
                    {
                        DisplayLog(" Draining Mommy of milk");
                        MotherEntity.Buffs.SetCustomVar("MilkLevel", 0f, true);
                        this.theEntity.Buffs.SetCustomVar("$foodAmountAdd", 50f, true);
                        this.theEntity.Buffs.SetCustomVar("$waterAmountAdd", 50f, true);
                    }
                }
            }
            // This is the actual item we want to drink out of. The above is just to deplete the water source.
            this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem("drinkJarBoiledWater", false));
            this.theEntity.Attack(true);
            // Then we want to fire off the event on the water we are drinking.
            this.theEntity.FireEvent(MinEventTypes.onSelfPrimaryActionEnd);

            DisplayLog(" Drinking");
            // restore the hand item.
            this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem(original.Name, false));
        }

        if (CheckIncentive(this.lstHungryBuffs))
        {
            DisplayLog("Hunger Check Block: " + checkBlock.Block.GetBlockName());
            ItemValue item = null;

            if (this.lstFoodBins.Contains(checkBlock.Block.GetBlockName()))
            {
                TileEntityLootContainer tileEntityLootContainer = this.theEntity.world.GetTileEntity(Voxel.voxelRayHitInfo.hit.clrIdx, new Vector3i(seekPos)) as TileEntityLootContainer;
                if (tileEntityLootContainer == null)
                {
                    return(false); // it's not a loot container.
                }
                // Check if it has any food on it.
                if (CheckContents(tileEntityLootContainer, this.lstFoodItems, "Food") != null)
                {
                    DisplayLog(" Found Food in food bin.");
                    item = GetItemFromContainer(tileEntityLootContainer, lstFoodItems, "Food");
                }
            }

            // Check the back pack
            else if (CheckContents(this.theEntity.lootContainer, this.lstFoodItems, "Food") != null)
            {
                DisplayLog(" Found Food in the backpack");
                item = GetItemFromContainer(this.theEntity.lootContainer, this.lstFoodItems, "Food");
            }

            if (item != null)
            {
                DisplayLog(" entity is eating: " + item.ItemClass.GetItemName());
                // Hold the food item.
                this.theEntity.inventory.SetBareHandItem(item);
                this.theEntity.Attack(true);
                // We want to consume the food, but the consumption of food isn't supported on the non-players, so just fire off the buff
                this.theEntity.FireEvent(MinEventTypes.onSelfPrimaryActionEnd);
                this.theEntity.FireEvent(MinEventTypes.onSelfHealedSelf);

                DisplayLog(" Eating");
                // restore the hand item.
                this.theEntity.inventory.SetBareHandItem(ItemClass.GetItem(original.Name, false));
            }
        }

        if (CheckIncentive(this.lstSanitationBuffs))
        {
            if (this.lstSanitation.Contains(checkBlock.Block.GetBlockName()))
            {
                this.theEntity.Buffs.CVars["$solidWasteAmount"] = 0;
            }

            // No toilets.
            if (this.lstSanitation.Count == 0)
            {
                // No Sanitation location? Let it go where you are.
                this.theEntity.Buffs.CVars["$solidWasteAmount"] = 0;

                // if there's no block, don't do anything.
                if (!String.IsNullOrEmpty(strSanitationBlock))
                {
                    Vector3i sanitationBlock = new Vector3i(this.theEntity.position);
                    this.theEntity.world.SetBlockRPC(sanitationBlock, Block.GetBlockValue(this.strSanitationBlock, false));
                }
            }
        }

        if (CheckIncentive(this.lstProductionBuffs))
        {
            if (this.lstBeds.Contains(checkBlock.Block.GetBlockName()))
            {
                DisplayLog(" My target block is in my approved list. ");
                TileEntityLootContainer tileEntityLootContainer = this.theEntity.world.GetTileEntity(Voxel.voxelRayHitInfo.hit.clrIdx, new Vector3i(seekPos)) as TileEntityLootContainer;
                if (tileEntityLootContainer != null)
                {
                    DisplayLog(" It's a TileEntity. That's good.");
                    foreach (ProductionItem item in this.lstProductionItem)
                    {
                        DisplayLog(" Adding " + item.item.GetItemId());
                        // Add the item to the loot container, and reset the cvar, if it's available.
                        tileEntityLootContainer.AddItem(new ItemStack(item.item, item.Count));
                        if (!String.IsNullOrEmpty(item.cvar) && this.theEntity.Buffs.HasBuff(item.cvar))
                        {
                            this.theEntity.Buffs.CVars[item.cvar] = 0;
                            this.theEntity.Buffs.RemoveBuff(this.strProductionFinishedBuff, true);
                        }
                    }
                }
                else
                {
                    DisplayLog(" Not a tile entity.");
                }
            }
            else
            {
                DisplayLog(" Not an approved block: " + checkBlock.Block.GetBlockName());
            }
        }
        else
        {
            DisplayLog(" No Bed Time buff incentive");
        }

        DisplayLog("After: " + this.theEntity.ToString());
        this.theEntity.SetInvestigatePosition(Vector3.zero, 0);
        this.theEntity.Buffs.AddBuff("buffMaslowCoolDown", -1, true);
        return(false);
    }
        public static bool Prefix(XUiC_ItemStack __instance, bool ___bLocked, bool ___isDragAndDrop)
        {
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            // Make sure we are dealing with legitimate stacks.
            if (__instance.ItemStack.IsEmpty())
            {
                return(true);
            }

            if (__instance.ItemStack.itemValue == null)
            {
                return(true);
            }

            if (___bLocked && ___isDragAndDrop)
            {
                return(true);
            }

            // Reset the durability
            //__instance.durability.IsVisible = false;

            // If the item class has a SpoilageTime, that means it can spoil over time.
            if (__instance.ItemStack.itemValue.ItemClass != null && __instance.ItemStack.itemValue.ItemClass.Properties.Contains("Spoilable"))
            {
                String strDisplay        = "XUiC_ItemStack: " + __instance.ItemStack.itemValue.ItemClass.GetItemName();
                float  DegradationMax    = 0f;
                float  DegradationPerUse = 0f;

                if (__instance.ItemStack.itemValue.ItemClass.Properties.Contains("SpoilageMax"))
                {
                    DegradationMax = __instance.ItemStack.itemValue.ItemClass.Properties.GetFloat("SpoilageMax");
                }

                if (__instance.ItemStack.itemValue.ItemClass.Properties.Contains("SpoilagePerTick"))
                {
                    DegradationPerUse = __instance.ItemStack.itemValue.ItemClass.Properties.GetFloat("SpoilagePerTick");
                }

                // By default, have a spoiler hit every 100 ticks, but allow it to be over-rideable in the xml.
                int TickPerLoss = 100;

                // Check if there's a Global Ticks Per Loss Set
                BlockValue ConfigurationBlock = Block.GetBlockValue("ConfigFeatureBlock");
                TickPerLoss = int.Parse(Configuration.GetPropertyValue("FoodSpoilage", "TickPerLoss"));

                // Check if there's a item-specific TickPerLoss
                if (__instance.ItemStack.itemValue.ItemClass.Properties.Contains("TickPerLoss"))
                {
                    TickPerLoss = __instance.ItemStack.itemValue.ItemClass.Properties.GetInt("TickPerLoss");
                }
                strDisplay += " Ticks Per Loss: " + TickPerLoss;

                // NextSpoilageTick will hold the world time + how many ticks until the next spoilage.
                if (__instance.ItemStack.itemValue.NextSpoilageTick == 0)
                {
                    __instance.ItemStack.itemValue.NextSpoilageTick = (int)GameManager.Instance.World.GetWorldTime() + TickPerLoss;
                }

                // Throttles the amount of times it'll trigger the spoilage, based on the TickPerLoss
                if (__instance.ItemStack.itemValue.NextSpoilageTick < (int)GameManager.Instance.World.GetWorldTime())
                {
                    // How much spoilage to apply
                    float PerUse = DegradationPerUse;

                    // Check if there's a player involved, which could change the spoilage rate.
                    //EntityPlayerLocal player = GameManager.Instance.World.GetPrimaryPlayer();
                    //if(player)
                    //   PerUse = EffectManager.GetValue(PassiveEffects.DegradationPerUse, __instance.ItemStack.itemValue, 1f, player, null, __instance.ItemStack.itemValue.ItemClass.ItemTags, true, true, true, true, 1, true);
                    //else
                    //   PerUse = EffectManager.GetValue(PassiveEffects.DegradationPerUse, __instance.ItemStack.itemValue, 1f, null, null, __instance.ItemStack.itemValue.ItemClass.ItemTags, true, true, true, true, 1, true);

                    float BasePerUse = PerUse;
                    strDisplay += " Base Spoil: " + PerUse;

                    float containerValue = 0;
                    // Additional Spoiler flags to increase or decrease the spoil rate
                    switch (__instance.StackLocation)
                    {
                    case XUiC_ItemStack.StackLocationTypes.ToolBelt:      // Tool belt Storage check
                        containerValue = float.Parse(Configuration.GetPropertyValue("FoodSpoilage", "Toolbelt"));
                        strDisplay    += " Storage Type: Tool Belt ( " + containerValue + " )";
                        PerUse        += containerValue;

                        break;

                    case XUiC_ItemStack.StackLocationTypes.Backpack:            // Back pack storage check
                        containerValue = float.Parse(Configuration.GetPropertyValue("FoodSpoilage", "Backpack"));
                        strDisplay    += " Storage Type: Backpack ( " + containerValue + " )";
                        PerUse        += containerValue;

                        break;

                    case XUiC_ItemStack.StackLocationTypes.LootContainer:        // Loot Container Storage check
                        TileEntityLootContainer container = __instance.xui.lootContainer;
                        if (container != null)
                        {
                            BlockValue Container         = GameManager.Instance.World.GetBlock(container.ToWorldPos());
                            String     lootContainerName = Localization.Get(Block.list[Container.type].GetBlockName());
                            strDisplay += " " + lootContainerName;

                            containerValue = float.Parse(Configuration.GetPropertyValue("FoodSpoilage", "Container"));
                            strDisplay    += " Storage Type: Container ( " + containerValue + " )";
                            PerUse        += containerValue;

                            if (Container.Block.Properties.Contains("PreserveBonus"))
                            {
                                strDisplay += " Preservation Bonus ( " + Container.Block.Properties.GetFloat("PreserveBonus") + " )";
                                PerUse     -= Container.Block.Properties.GetFloat("PreserveBonus");
                            }
                        }
                        else
                        {
                            strDisplay += " Storage Type: Container ( Undefined Configuration Block: +10 )";
                            PerUse     += 10;
                        }

                        break;

                    case XUiC_ItemStack.StackLocationTypes.Creative:      // Ignore Creative Containers
                        return(true);

                    default:
                        containerValue = float.Parse(Configuration.GetPropertyValue("FoodSpoilage", "Container"));
                        strDisplay    += " Storage Type: Generic ( Default Container) ( " + containerValue + " )";
                        PerUse        += containerValue;
                        break;
                    }


                    strDisplay += " Spoiled This Tick: " + (PerUse - BasePerUse);
                    float MinimumSpoilage = float.Parse(Configuration.GetPropertyValue("FoodSpoilage", "MinimumSpoilage"));
                    MinimumSpoilage = Math.Max(0.1f, MinimumSpoilage);

                    // Worse case scenario, no matter what, Spoilage will increment.
                    if (PerUse <= MinimumSpoilage)
                    {
                        strDisplay += " Minimum spoilage Detected (PerUse: " + PerUse + " Minimum: " + MinimumSpoilage + " )";
                        PerUse      = MinimumSpoilage;
                    }
                    // Calculate how many Spoils we may have missed over time. If we left our base and came back to our storage box, this will help accurately determine how much
                    // spoilage should apply.
                    String temp = "World Time: " + (int)GameManager.Instance.World.GetWorldTime() + " Minus NextSpoilageTick: " + __instance.ItemStack.itemValue.NextSpoilageTick + " Tick Per Loss: " + TickPerLoss;
                    AdvLogging.DisplayLog(AdvFeatureClass, temp);

                    int TotalSpoilageMultiplier = (int)(GameManager.Instance.World.GetWorldTime() - __instance.ItemStack.itemValue.NextSpoilageTick) / TickPerLoss;
                    if (TotalSpoilageMultiplier == 0)
                    {
                        TotalSpoilageMultiplier = 1;
                    }

                    float TotalSpoilage = PerUse * TotalSpoilageMultiplier;
                    strDisplay += " Spoilage Ticks Missed: " + TotalSpoilageMultiplier;
                    strDisplay += " Total Spoilage: " + TotalSpoilage;
                    __instance.ItemStack.itemValue.CurrentSpoilage += TotalSpoilage;

                    strDisplay += " Next Spoilage Tick: " + (int)GameManager.Instance.World.GetWorldTime() + TickPerLoss;
                    strDisplay += " Recorded Spoilage: " + __instance.ItemStack.itemValue.CurrentSpoilage;
                    AdvLogging.DisplayLog(AdvFeatureClass, strDisplay);

                    // Update the NextSpoilageTick value
                    __instance.ItemStack.itemValue.NextSpoilageTick = (int)GameManager.Instance.World.GetWorldTime() + TickPerLoss;
                    __instance.ItemStack.itemValue.NextSpoilageTick = (int)GameManager.Instance.World.GetWorldTime() + TickPerLoss;

                    // If the spoil time is is greater than the degradation, loop around the stack, removing each layer of items.
                    while (DegradationMax <= __instance.ItemStack.itemValue.CurrentSpoilage)
                    //if(DegradationMax <= __instance.ItemStack.itemValue.CurrentSpoilage)
                    {
                        // If not defined, set the foodRottingFlesh as a spoiled product. Otherwise use the global / item.
                        String strSpoiledItem = Configuration.GetPropertyValue("FoodSpoilage", "SpoiledItem");
                        if (string.IsNullOrEmpty(strSpoiledItem))
                        {
                            strSpoiledItem = "foodRottingFlesh";
                        }

                        if (__instance.ItemStack.itemValue.ItemClass.Properties.Contains("SpoiledItem"))
                        {
                            strSpoiledItem = __instance.ItemStack.itemValue.ItemClass.Properties.GetString("SpoiledItem");
                        }



                        //EntityPlayerLocal player = __instance.xui.playerUI.entityPlayer;
                        EntityPlayerLocal player = GameManager.Instance.World.GetPrimaryPlayer();
                        if (player)
                        {
                            int Count = 1;

                            if (Configuration.CheckFeatureStatus(AdvFeatureClass, "FullStackSpoil"))
                            {
                                AdvLogging.DisplayLog(AdvFeatureClass, __instance.ItemStack.itemValue.ItemClass.GetItemName() + ":Full Stack Spoil");
                                Count = __instance.ItemStack.count;
                                __instance.ItemStack = new ItemStack(ItemClass.GetItem(strSpoiledItem, false), Count);
                                break;
                            }
                            ItemStack itemStack = new ItemStack(ItemClass.GetItem(strSpoiledItem, false), Count);

                            if (itemStack.itemValue.ItemClass.GetItemName() != __instance.ItemStack.itemValue.ItemClass.GetItemName())
                            {
                                if (!LocalPlayerUI.GetUIForPlayer(player).xui.PlayerInventory.AddItem(itemStack, true))
                                {
                                    player.world.gameManager.ItemDropServer(itemStack, player.GetPosition(), Vector3.zero, -1, 60f, false);
                                }
                            }
                        }

                        if (__instance.ItemStack.count > 2)
                        {
                            AdvLogging.DisplayLog(AdvFeatureClass, __instance.ItemStack.itemValue.ItemClass.GetItemName() + ": Reducing Stack by 1");
                            __instance.ItemStack.count--;
                            __instance.ItemStack.itemValue.CurrentSpoilage -= DegradationMax;
                        }
                        else
                        {
                            AdvLogging.DisplayLog(AdvFeatureClass, __instance.ItemStack.itemValue.ItemClass.GetItemName() + ": Stack Depleted. Removing.");
                            __instance.ItemStack = new ItemStack(ItemValue.None.Clone(), 0);
                            break;  // Nothing more to spoil
                        }
                        // break;
                    }
                    __instance.ForceRefreshItemStack();
                }
            }

            return(true);
        }
예제 #25
0
 public static bool GameManager_OpenTileEntityAllowed_Prefix(ref bool __result, ref bool __state, int _entityIdThatOpenedIt, TileEntity _te)
 {
     try
     {
         ClientInfo cInfo = PersistentOperations.GetClientInfoFromEntityId(_entityIdThatOpenedIt);
         if (cInfo != null)
         {
             if (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > 0 &&
                 GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > 0)
             {
                 if (DroppedBagProtection.IsEnabled)
                 {
                     if (_te is TileEntityLootContainer)
                     {
                         TileEntityLootContainer lootContainer = _te as TileEntityLootContainer;
                         if (lootContainer.bPlayerBackpack)
                         {
                             if (!DroppedBagProtection.IsAllowed(_entityIdThatOpenedIt, lootContainer))
                             {
                                 Phrases.Dict.TryGetValue("DroppedBagProtection1", out string phrase);
                                 ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                 __result = false;
                                 return(false);
                             }
                         }
                     }
                 }
                 if (Shutdown.UI_Locked)
                 {
                     if (_te is TileEntityLootContainer)
                     {
                         TileEntityLootContainer lootContainer = _te as TileEntityLootContainer;
                         if (lootContainer.bPlayerBackpack)
                         {
                             return(true);
                         }
                     }
                     if (_te is TileEntityWorkstation || _te is TileEntityLootContainer || _te is TileEntitySecureLootContainer ||
                         _te is TileEntityVendingMachine || _te is TileEntityTrader)
                     {
                         if (_te is TileEntityTrader)
                         {
                             __state = true;
                         }
                         Phrases.Dict.TryGetValue("Shutdown3", out string phrase);
                         ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                         __result = false;
                         return(false);
                     }
                 }
                 if (WorkstationLock.IsEnabled && _te is TileEntityWorkstation)
                 {
                     EntityPlayer entityPlayer = PersistentOperations.GetEntityPlayer(cInfo.entityId);
                     if (entityPlayer != null)
                     {
                         EnumLandClaimOwner owner = PersistentOperations.ClaimedByWho(cInfo.CrossplatformId, new Vector3i(entityPlayer.position));
                         if (owner != EnumLandClaimOwner.Self && owner != EnumLandClaimOwner.Ally && !PersistentOperations.ClaimedByNone(new Vector3i(entityPlayer.position)))
                         {
                             Phrases.Dict.TryGetValue("WorkstationLock1", out string phrase);
                             ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                             __result = false;
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Injections.GameManager_OpenTileEntityAllowed_Prefix: {0}", e.Message));
     }
     return(true);
 }