/// <summary> /// Ticks for update this instance. /// </summary> public void Tick() { bool isInCombatState = this._level.IsInCombatState(); LogicArrayList <LogicComponent> components = this._components[0]; for (int i = 0; i < components.Count; i++) { LogicComponent component = components[i]; if (component.IsEnabled()) { component.Tick(); } } for (int i = isInCombatState ? 1 : 2; i < 17; i++) { components = this._components[i]; for (int j = 0; j < components.Count; j++) { LogicComponent component = components[j]; if (component.IsEnabled()) { component.Tick(); } } } }
/// <summary> /// Gets the closest component. /// </summary> public LogicComponent GetClosestComponent(int x, int y, LogicComponentFilter filter) { LogicArrayList <LogicComponent> components = this._components[filter.GetComponentType()]; LogicComponent minDistanceComponent = null; if (components.Count > 0) { int idx = 0; int minDistance = 0; do { LogicComponent component = components[idx]; if (filter.TestComponent(component)) { int distance = component.GetParent().GetPosition().GetDistanceSquaredTo(x, y); if (distance < minDistance || minDistanceComponent == null) { minDistance = distance; minDistanceComponent = component; } } } while (++idx != components.Count); } return(minDistanceComponent); }
/// <summary> /// Removes the specified component. /// </summary> public void RemoveComponent(LogicComponent component) { LogicArrayList <LogicComponent> components = this._components[component.GetComponentType()]; int index = -1; for (int i = 0; i < components.Count; i++) { LogicComponent tmp = components[i]; if (tmp.Equals(component)) { index = i; break; } } if (index != -1) { components.Remove(index); } }
/// <summary> /// Adds the specified component to this instance. /// </summary> public void AddComponent(LogicComponent component) { this._components[component.GetComponentType()].Add(component); }