Пример #1
0
        public static bool CanLoot(this HarvestableObject obj, LocalPlayerCharacterView localPlayer)
        {
            if (!obj.IsHarvestable())
            {
                return(false);
            }

            bool requiresTool       = obj.RequiresTool();
            EquipmentItemProxy tool = obj.GetTool(localPlayer);

            if (requiresTool && !tool)
            {
                return(false);
            }

            //TODO: Implement converters
            GuiDurableItemProxy toolProxy = ClientTools.GetStackProxy(tool).GuiItemProxy_Internal as a9h;

            int durability = toolProxy ? ClientTools.SomeCalculationWithUnfloatyFloats(tool.GetUnfloatyFloat(), toolProxy.GetUnfloatyFloat()) : -1;

            if (requiresTool && durability <= 10)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public override bool preform()
        {
            this.cooldown -= Time.deltaTime;

            if (this.unit.canHoldMore())
            {
                // Find something to harvest.
                if (this.target == null)
                {
                    this.target = (HarvestableObject)this.unit.map.getClosestObject(this.unit.getFootPos(), HarvestableObject.predicateIsHarvestable);
                }

                if (this.target == null)
                {
                    return(false); // No target to be found, stop executing.
                }
                else
                {
                    this.moveHelper.setDestination(this.target);
                }

                // Harvest from the nearby object if it is in range.
                if (this.cooldown <= 0 && this.func())
                {
                    if (this.target.harvest(this.unit))
                    {
                        // Target was consumed.
                        this.target = null;
                    }
                    this.cooldown = Constants.BUILDER_STRIKE_RATE;
                }
            }
            else
            {
                // Full, drop off resources.
                if (this.dropoffPoint == null)
                {
                    // find a drop off point.
                    this.dropoffPoint = this.findEntityOfType <BuildingStoreroom>(this.unit.getPos(), -1, false);

                    if (this.dropoffPoint == null)
                    {
                        // No drop off point, stop executing, as we can't drop off what we have.
                        return(false);
                    }
                    else
                    {
                        // this.setDestination
                    }
                }
            }

            return(true);
        }
Пример #3
0
        public static ResourceType?GetResourceType(this HarvestableObject obj)
        {
            try
            {
                var resourceTypeString = obj.GetResourceDescriptor().ResourceType;
                if (resourceTypeString.Contains("_"))
                {
                    resourceTypeString = resourceTypeString.Substring(0, resourceTypeString.IndexOf("_"));
                }

                return((ResourceType)Enum.Parse(typeof(ResourceType), resourceTypeString, true));
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
 public TaskHarvestNearby(UnitBuilder unit, HarvestableObject target) : base(unit)
 {
     this.target = target;
 }
Пример #5
0
 public static bool RequiresTool(this HarvestableObject obj)
 {
     return(obj.GetTierDescriptor().RequiresTool());
 }
Пример #6
0
 public static int GetTier(this HarvestableObject obj)
 {
     return(obj.GetResourceDescriptor().Tier);
 }
Пример #7
0
 public static EquipmentItemProxy GetTool(this HarvestableObject obj, LocalPlayerCharacterView player)
 {
     return(obj.GetTool(player.GetLocalPlayerCharacter(), false));
 }