Пример #1
0
    public static bool RequestUseItem(ISimGameWorldReadWriteAccessor accessor, Entity actor, Entity item, GameAction.UseParameters parameters = null)
    {
        if (!CommonReads.CanUseItem(accessor, actor, item, out ItemUnavailablityReason unavailabilityReason))
        {
            Log.Warning($"Instigator {accessor.GetNameSafe(actor)} cannot use item {accessor.GetNameSafe(item)} because of {unavailabilityReason}");
            return(false);
        }

        accessor.TryGetComponent(item, out ItemAction itemAction);

        CommonWrites.RequestExecuteGameAction(accessor, item, itemAction, parameters);

        // reduce consumable amount
        if (accessor.GetComponent <StackableFlag>(item))
        {
            CommonWrites.DecrementItem(accessor, item, actor);
        }

        // reduce instigator AP
        if (accessor.TryGetComponent(item, out ItemSettingAPCost itemActionPointCost) && itemActionPointCost.Value != 0)
        {
            CommonWrites.ModifyStatFix <ActionPoints>(accessor, actor, -itemActionPointCost.Value);
        }

        // Cooldown
        if (accessor.TryGetComponent(item, out ItemTimeCooldownData itemTimeCooldownData))
        {
            accessor.SetOrAddComponent(item, new ItemCooldownTimeCounter()
            {
                Value = itemTimeCooldownData.Value
            });
        }

        return(true);
    }
 public static void RequestPull(ISimGameWorldReadWriteAccessor accessor, Entity entity, fix2 Destination, fix Speed)
 {
     accessor.SetOrAddComponent(entity, new PullData()
     {
         Destination = Destination,
         Speed       = Speed,
         StartTime   = accessor.Time.ElapsedTime
     });
 }