public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; List <InventorySlot> inventorySlots = target.entityType.canBeInInventorySlots.Select(x => x.inventorySlot).ToList(); // TODO: Just drop it for now - do better logic later List <InventorySlot> possibleSlots = inventorySlots.Intersect(agent.agentType.inventorySlots).ToList(); if (possibleSlots.Count == 0) { Debug.LogError(agent.name + ": ClearInventorySlotsOCT - unable to find a slot to clear."); return(false); } // This will do nothing if the target doesn't have all of the amount // TODO: Add in options to handle not enough inventory InventoryType.Item item = target.inventoryType.Remove(target, possibleSlots[0]); if (item == null) { return(false); } item.entity.inventoryType.Dropped(item.entity, item.inventorySlot); return(true); }
public bool Check(Agent agent, InventoryType.Item item, ActionType actionType) { if (!actionTypes.Contains(actionType)) { return(false); } return(itemCondition.Check(agent, actionType, null, item.inventorySlot, 0, false, true, true)); }
// Evaluates based on the current ActionType modifiers from each Entity // For example: MeleeAttack can use this to pick the weapon with the largest modifier public override float Evaluate(Agent agent, Entity entity, Mapping mapping, bool forInventory) { ActionType actionType = mapping.mappingType.actionType; ActionType otherActionType = null; if (mapping.target is Agent otherAgent && otherAgent.decider.CurrentMapping != null) { otherActionType = otherAgent.decider.CurrentMapping.mappingType.actionType; } float value = 0f; // The entity could already be in inventory or the Agent could be going to get it in a chained mapping if (entity.inEntityInventory == agent) { // Does it match? value = agent.inventoryType.CalcOnActionAttributeTypeModifiers(agent, attributeType, actionType, otherActionType, entity, modifierType, isTarget); // TODO: If not if slots got switched could it match? Possible to look for a switch mapping? } else { // TODO: Should I know the slot by now? I think it has to figure it out before getting here. // Add InventoryTargetSlot to Mapping? agent.inventoryType.FindInventorySlotsToClear(agent, entity.entityType, out InventorySlot inventorySlot, 1, true); if (inventorySlot == null) { Debug.LogError(agent.name + ": ActionTypeModifierTF is unable to find a slot for a possible Entity = " + entity.name); return(0f); } InventoryType.Item item = new InventoryType.Item() { inventorySlot = inventorySlot, entity = entity }; value = agent.inventoryType.CalcOnActionAttributeTypeModifiers(agent, attributeType, actionType, otherActionType, item, modifierType, isTarget); } // This min and max of the curve define the range of values for normalizing the value // For example if the value is 10 and the min is 0 and max is 50 - 1/5 = 0.2 would get input to curve // Curves are always 0-1 on input axis (x) and 0-1 on output axis (y) if (minMaxCurve == null) { Debug.LogError("ActionTypeModifierTF is missing a Min Max Curve. Please Fix."); return(0f); } //Debug.Log(agent.name + ": ActionTypeModifierTF - Entity = " + entity.name + " - value = " + value); return(minMaxCurve.NormAndEvalIgnoreMinMax(value, minMaxCurve.min, minMaxCurve.max)); }
// TODO: Just handles moving to empty slot - need to handle swapping entities public void SwitchInventorySlots(InventoryType.Item itemToMove, InventorySlot newSlot) { GameObject gameObjectToMove = itemToMove.entity.gameObject; gameObjectToMove.transform.parent = GetSlotMapping(newSlot, out bool makeDisabled).transform; gameObjectToMove.transform.localPosition = Vector3.zero; if (newSlot.slotType != InventorySlot.SlotType.Invisible && !makeDisabled) { gameObjectToMove.SetActive(true); } else { gameObjectToMove.SetActive(false); } }
public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; Entity projectileEntity; if (outputChange.valueType == OutputChange.ValueType.None) { OutputChange previousOutputChange = outputChange.Previous(mapping.mappingType); projectileEntity = agent.inventoryType.GetFirstEntityofEntityType(agent, previousOutputChange.entityType); } else { projectileEntity = mapping.inventoryTargets[(int)outputChange.floatValue]; } // Remove projectile from shooter's inventory InventoryType.Item projectileItem = agent.inventoryType.Remove(agent, projectileEntity); if (projectileItem == null) { Debug.LogError(agent.name + ": ThrowProjectileOCT - No projectile WorldObject - " + projectileEntity.name); return(false); } // TODO: This is strange here - Need a Throw method in InventoryType to handle this? projectileItem.entity.transform.parent = null; projectileItem.entity.inEntityInventory = null; // Throw it Projectile projectile = projectileItem.entity.GetComponent <Projectile>(); if (projectile == null) { Debug.LogError(agent.name + ": ThrowProjectileOCT - No Projectile Component on the projectile WorldObject " + projectileEntity.name); return(false); } projectile.target = target.gameObject; return(true); }
public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; if (agent.inEntityInventory == null) { Debug.Log(agent.name + ": InventoryRemoveSelfOCT - Agent is not in any inventory."); return(false); } Entity inEntity = agent.inEntityInventory; InventoryType.Item item = inEntity.inventoryType.Remove(inEntity, agent); if (item == null) { Debug.LogError(agent.name + ": InventoryRemoveSelfOCT unable to find agent in " + inEntity.name); return(false); } agent.inventoryType.Dropped(agent, item.inventorySlot); return(true); }
public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; // Make sure Agent is holding something that can shoot projectiles // These checks should be done by the ICs so maybe ckip them here? // TODO: Be nice to have the inventory entity target for this WorldObject shooter = agent.inventoryType.GetFirstEntityInSlot(agent, shooterSlot) as WorldObject; if (shooter == null) { Debug.LogError(agent.name + ": ShootProjectileOCT - No ranged weapon equipped"); return(false); } // Remove projectile from shooter's inventory InventoryType.Item projectileItem = shooter.inventoryType.Remove(shooter, projectileSlot); if (projectileItem == null) { Debug.LogError(agent.name + ": ShootProjectileOCT - No projectileWorldObject in " + shooter.name); return(false); } projectileItem.entity.transform.parent = null; // Shoot it Projectile projectile = projectileItem.entity.GetComponent <Projectile>(); if (projectile == null) { Debug.LogError(agent.name + ": ShootProjectileOCT - No projectile Component on the projectileWorldObject " + projectileItem.entity.name); return(false); } projectile.target = target.gameObject; return(true); }
public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; Entity entityToThrow = mapping.inventoryTargets[outputChange.inventoryTypeGroupMatchIndex]; if (entityToThrow == null) { Debug.LogError(agent.name + ": ThrowEntityOCT - No entity to throw found."); return(false); } // Remove from inventory InventoryType.Item item = agent.inventoryType.Remove(agent, entityToThrow); if (item == null) { Debug.LogError(agent.name + ": ThrowEntityOCT - No entity to throw found in agent's inventory."); return(false); } Vector3 targetPosition = target.transform.position; if (outputChange.unityObject != null) { // Move direction by random degrees MinMaxCurve minMaxCurve = outputChange.unityObject as MinMaxCurve; float degrees = minMaxCurve.EvalRandom(); // Rotate targetPosition relative to agent.position by degrees Vector3 forceVector = Quaternion.Euler(0, 0, degrees) * ((Vector2)(targetPosition - agent.transform.position)).normalized; Debug.DrawRay(agent.transform.position, forceVector, Color.white, 5f); targetPosition = forceVector + agent.transform.position; } agent.inventoryType.Thrown(entityToThrow, agent, item.inventorySlot, targetPosition, outputChange.floatValue); return(true); }