private bool DoApplyItem(Entity user, Entity item, Entity target, InteractsWith interaction) { if (item == target) //Can't apply item to itself! { return(false); } var itemComponent = item.GetComponent <BasicItemComponent>(ComponentFamily.Item); if (itemComponent != null) { //TODO move this logic somewhere that makes more sense than in the component itemComponent.ApplyTo(target, interaction, user); } return(true); }
/// <summary> /// Apply this item's capabilities to a target entity /// This finds all onboard capability modules that can interact with a given object type, /// sorted by priority. Only one thing will actually execute, depending on priority. /// ApplyTo returns true if it successfully interacted with the target, false if not. /// </summary> /// <param name="target">Target entity for interaction</param> protected virtual void ApplyCapabilities(Entity target, InteractsWith targetType, Entity sourceActor) { IOrderedEnumerable <ItemCapability> capstoapply = from c in capabilities.Values where (c.interactsWith & targetType) == targetType orderby c.priority descending select c; foreach (ItemCapability capability in capstoapply) { if (capability.ApplyTo(target, sourceActor)) { break; } } }
/// <summary> /// Apply this item's capabilities to a target entity /// This finds all onboard capability modules that can interact with a given object type, /// sorted by priority. Only one thing will actually execute, depending on priority. /// ApplyTo returns true if it successfully interacted with the target, false if not. /// </summary> /// <param name="target">Target entity for interaction</param> protected virtual void ApplyCapabilities(Entity target, InteractsWith targetType, Entity sourceActor) { IOrderedEnumerable<ItemCapability> capstoapply = from c in capabilities.Values where (c.interactsWith & targetType) == targetType orderby c.priority descending select c; foreach (ItemCapability capability in capstoapply) { if (capability.ApplyTo(target, sourceActor)) break; } }
/// <summary> /// Applies this item to the target entity. /// </summary> /// <param name="targetEntity">Target entity</param> /// <param name="targetType">Type of entity, Item, LargeObject, or Actor</param> public virtual void ApplyTo(Entity targetEntity, InteractsWith targetType, Entity sourceActor) { //can be overridden in children to sort of bypass the capability system if needed. ApplyCapabilities(targetEntity, targetType, sourceActor); }
private bool DoApplyItem(Entity user, Entity item, Entity target, InteractsWith interaction) { if (item == target) //Can't apply item to itself! return false; var itemComponent = item.GetComponent<BasicItemComponent>(ComponentFamily.Item); if (itemComponent != null) { //TODO move this logic somewhere that makes more sense than in the component itemComponent.ApplyTo(target, interaction, user); } return true; }