/** * Initialise the grid. */ override protected void Init() { initialised = true; grid = new IGridObject[gridSize, gridSize]; FillUnusableGrid(); gridObjects = new Dictionary <IGridObject, List <GridPosition> > (); }
public void DeregisterAgent(Agent agent) { if (obstacle == agent as IGridObject) { obstacle = null; } }
public override IEnumerator OnTowerClick(IGridObject tower, PointerEventData eventData) { yield return(GameManager.Instance.UiManager.HideCancelButton()); yield return(GameManager.Instance.UiManager.HideTowerActionBar()); yield return(StateUtility.OnTowerClick(tower, eventData)); }
public bool GetEnableDisablePaging(IGridObject obj) { if (obj.GridType == GridTypeValue.Gxui) return false; if (DefaultPagingButtons) return false; return EnableDisablePaging; }
public bool GetMaxPage(IGridObject obj) { if (obj.GridType == GridTypeValue.Gxui) return false; if (DefaultPagingButtons) return false; return MaxPage; }
public MovingPath FindPath(IGridObject goThis, Vector3 endPoint, float speed) { if (Find(goThis, endPoint, ref speed)) { return(new MovingPath(_points.ToArray(), speed)); } return(null); }
public void OnTowerClick(IGridObject tower, PointerEventData eventData) { if (IsRunning) { return; } StartCoroutine(SafeStart(_state.OnTowerClick(tower, eventData))); }
/*public void ClearEmpties() * { * List<Vector3> empties = new List<Vector3>(); * foreach(KeyValuePair<Vector3, List<IGridObject>> pair in _objects) * { * pair.Value.RemoveAll(o=> o as GridObject == null); * if(pair.Value.Count == 0) * { * empties.Add(pair.Key); * } * } * foreach(Vector3 empty in empties) * _objects.Remove(empty); * }*/ public void MoveObjectFromPosToPos(IGridObject obj, Vector3 oldPos, Vector3 newPos, bool force) { if (oldPos != newPos || force) //optimize { RemoveObject(oldPos, obj); SetToCell(newPos, obj); } }
virtual public void RemoveObject(IGridObject gridObject) { foreach (GridPosition g in gridObjects[gridObject]) { grid[g.x, g.y] = null; } gridObjects.Remove(gridObject); }
public void removeObject(IGridObject obj) { if (obj == null) { return; } m_arr_grid_obj.Remove(obj); }
public void RegisterAgent(Agent agent) { //if (obstacle != null) //{ // Debug.LogWarning(string.Format("{0} has two obstacles, the original was overridden by {1}", gameObject.name, agent.agentName)); //} obstacle = agent; }
virtual public void RemoveObjectAtPosition(GridPosition position) { IGridObject g = GetObjectAtPosition(position); if (g != null) { RemoveObject(g); } }
virtual public bool CanObjectBePlacedAtPosition(IGridObject gridObject, GridPosition position) { GridPosition newPosition; foreach (GridPosition g in gridObject.Shape) { newPosition = position + g; if (newPosition.x < 0 || newPosition.x >= grid.GetLength(0)) return false; if (newPosition.y < 0 || newPosition.y >= grid.GetLength(1)) return false; if (grid[newPosition.x, newPosition.y] != null && grid[newPosition.x, newPosition.y] != gridObject) return false; } return true; }
public T GetFromCell <T>(Vector3 pos) { IGridObject o = GetFromCell(pos); if (o == null) { return(default(T)); } return(o.GetProperty <T>()); }
public T FindFromCell <T>(Vector3 pos) { IGridObject go = null; List <IGridObject> list; if (_objects.TryGetValue(pos, out list) && list.Count > 0) { go = list.Find(o => /*o as GridObject &&*/ o.GetProperty <T>() != null); } return(go != null?go.GetProperty <T>() : default(T)); }
virtual public void AddObjectAtPosition(IGridObject gridObject, GridPosition position) { List<GridPosition> gridPosisitons = new List<GridPosition>(); GridPosition newPosition; foreach (GridPosition g in gridObject.Shape) { newPosition = position + g; gridPosisitons.Add (newPosition); grid[newPosition.x, newPosition.y] = gridObject; } gridObjects.Add(gridObject, gridPosisitons); }
/*public IGridObject GetTopCell(Vector3 pos) * { * pos.y = -1; * IGridObject topCell = null; * int k = 5;//top * while(k-->0) * { * pos = pos+Vector3.up; * if(GetFromCell(pos)!=null) * topCell = GetFromCell(pos); * } * return topCell; * } * * public T GetTopCell<T>(Vector3 pos) * { * pos.y = -1; * T topCell = default(T); * int k = 5;//top * while(k-->0) * { * pos = pos+Vector3.up; * if(GetFromCell<T>(pos)!=null) * topCell = GetFromCell<T>(pos); * } * return topCell; * }*/ public IGridObject GetFromCell(Vector3 pos) { IGridObject go = null; List <IGridObject> list; if (_objects.TryGetValue(pos, out list) && list.Count > 0) { go = list[0]; //.Find(o=>o as GridObject); } return(go); }
// Use this for initialization void Start() { directions = new IGridObject[] { new Hex(1, -1, 0), new Hex(1, 0, -1), new Hex(0, 1, -1), new Hex(-1, 1, 0), new Hex(-1, 0, 1), new Hex(0, -1, 1) }; diagonals = new IGridObject[] { new Hex(2, -1, -1), new Hex(1, 1, -2), new Hex(-1, 2, -1), new Hex(-2, 1, 1), new Hex(-1, -1, 2), new Hex(1, -2, 1) }; }
// Use this for initialization void Start() { directions = new IGridObject[]{ new Hex( 1, -1, 0 ), new Hex( 1, 0, -1 ), new Hex( 0, 1, -1 ), new Hex( -1, 1, 0 ), new Hex( -1, 0, 1 ), new Hex( 0, -1, 1 ) }; diagonals = new IGridObject[]{ new Hex( 2, -1, -1 ), new Hex( 1, 1, -2 ), new Hex( -1, 2, -1 ), new Hex( -2, 1, 1 ), new Hex( -1, -1, 2 ), new Hex( 1, -2, 1 ) }; }
public void RemoveObject(Vector3 oldPos, IGridObject obj) { List <IGridObject> list; if (_objects.TryGetValue(oldPos, out list)) { list.Remove(obj); if (list.Count == 0) { _objects.Remove(oldPos); } } }
public static IEnumerator OnTowerClick(IGridObject tower, PointerEventData eventData) { GameManager.Instance.SelectionManager.DeselectAll(); var target = tower as Tower; if (eventData.button != PointerEventData.InputButton.Left || target == null) { yield return(ReturnToWait()); } GameManager.Instance.SelectionManager.SelectedTower = target; GameManager.Instance.StateMachine.SetState(new WaitForPlayerPickTowerActionState()); }
private string GridObjectName(IGridObject gridObject) { if (gridObject is TabElement) return TabName((TabElement)gridObject); if (gridObject is SelectionElement) return SelectionName((SelectionElement)gridObject); if (gridObject is PromptElement) return PromptName((PromptElement)gridObject); throw new TemplateException(Messages.FormatUnexpectedGridObjectType(gridObject.GetType().FullName)); }
virtual public void AddObjectAtPosition(IGridObject gridObject, GridPosition position) { List <GridPosition> gridPosisitons = new List <GridPosition>(); GridPosition newPosition; foreach (GridPosition g in gridObject.Shape) { newPosition = position + g; gridPosisitons.Add(newPosition); grid[newPosition.x, newPosition.y] = gridObject; } gridObjects.Add(gridObject, gridPosisitons); }
public void addObject(IGridObject obj) { if (obj == null) { return; } if (m_arr_grid_obj.Contains(obj)) { return; } m_arr_grid_obj.Add(obj); }
public void OnMoveFinished(IGridObject opponent) { _gridObject.Grid.GetAll <EnemyObject> ().ForEach(e => e.Initiative--); //1 атакует после свайпа всех вокруг себя. //2 атакует по линии в направлении места, где он был до свайпа. //3 после свайпа атакует 3 случайных противников на поле. if (opponent.GetProperty <EnemyObject> () != null) { switch (_attackType) { case AttackType.round: List <Vector3> cells = _gridObject.Grid.Utils.GetAroundCells(); foreach (Vector3 cell in cells) { EnemyObject e = _gridObject.Grid.GetFromCell <EnemyObject> (cell + _gridObject.GridPos); _showEffect(cell + _gridObject.GridPos); if (e != null) { e.Health -= _attackForse; } } break; case AttackType.line: Vector3 dir = _gridPosOnStartMove - _gridObject.GridPos; Vector3 currentPos = _gridPosOnStartMove; while (_gridObject.Grid.Utils.IsInside(currentPos)) { EnemyObject e = _gridObject.Grid.GetFromCell <EnemyObject> (currentPos); _showEffect(currentPos); if (e != null) { e.Health -= _attackForse; } currentPos += dir; } break; case AttackType.three_random: List <EnemyObject> enemies = _gridObject.Grid.GetAll <EnemyObject> (); for (int i = 0; i < 3; i++) { EnemyObject e = enemies [UnityEngine.Random.Range(0, enemies.Count)]; _showEffect(e.GridObject.GridPos); e.Health -= _attackForse; } break; } } }
public bool CanAdd(IGridObject o, int x, int y) { var space = o.Space(); bool result = ResourceState.instance.CanSpend(o.Price()); for (int i = x; i != x + space.Item2.Item1 && result; i++) { for (int j = y; j != y + space.Item2.Item2 && result; j++) { result = !(space.Item1[i - x, j - y] && this.matrix[i, j].Item1); } } return(result); }
public void Save() { List <Vector3Int> locations = new List <Vector3Int>(); List <EDirection> directions = new List <EDirection>(); List <string> types = new List <string>(); List <string> colours = new List <string>(); for (int y = 0; y < Depth; ++y) { for (int z = 0; z < Length; ++z) { for (int x = 0; x < Width; ++x) { GridObject obj = Tiles[x, y, z]; if (obj != null) { locations.Add(obj.ObjectGridLocation); directions.Add(obj.ObjectDirection); types.Add(obj.ObjectData.ObjectName); IGridObject objScript = obj.Object.GetComponentInChildren <IGridObject>(); colours.Add(objScript == null ? "" : objScript.Colour); DestroyGridObject(new Vector3Int(x, y, z)); } } } } string data = ""; for (int i = 0; i < locations.Count; ++i) { // Add object data += "PlaceObject("; data += "\"" + types[i] + "\", "; data += locations[i].x + ", " + locations[i].y + ", " + locations[i].z + ", "; data += "EDirection." + directions[i].ToString() + ", "; data += "\"" + colours[i] + "\""; data += ");\n"; } File.WriteAllText("Assets/Resources/Grid Saves/Test.txt", data); }
public void Remove(IGridObject o) { var position = o.GridPosition(); var space = o.Space(); int x = position.Item1; int y = position.Item2; for (int i = x; i != x + space.Item2.Item1; i++) { for (int j = y; j != y + space.Item2.Item2; j++) { if (space.Item1[i - x, j - y] && this.matrix[i, j].Item1) { this.matrix[i, j] = new Tuple <bool, IGridObject>(false, null); } } } o.kill(); }
public bool Pickup(GameObject obj) { Structure objStructure = obj.GetComponent <Structure>(); if (objStructure) { GlobalStructureModManager.Instance.ApplyMods(objStructure); } _highlighters = HighlighterCollection.Create(obj, GetHighlighterSet()); _highlighters.Highlight(); _obj = obj; _obj.SetActive(false); _model = UnityUtils.InstantiateMockGO(_obj); _placeable = obj.GetComponent <IGridObject>(); return(_placeable != null); }
public void SetToCell(Vector3 pos, IGridObject value) { if (value == null) { Debug.LogError("SetToCell " + pos + " null object"); } List <IGridObject> list; if (_objects.TryGetValue(pos, out list)) { list.Add(value); } else { _objects.Add(pos, new List <IGridObject>() { value }); } }
public void Put(IGridObject o, int x, int y) { ResourceState.instance.Spend(o.Price()); var space = o.Space(); for (int i = x; i != x + space.Item2.Item1; i++) { for (int j = y; j != y + space.Item2.Item2; j++) { if (space.Item1[i - x, j - y]) { if (this.matrix[i, j].Item2 != null) { this.Remove(this.matrix[i, j].Item2); } this.matrix[i, j] = new Tuple <bool, IGridObject>(true, o); } } } }
bool Find(IGridObject goThis, Vector3 endPoint, ref float speed) { _points.Clear(); IGrid grid = goThis.Grid; _points.Insert(0, endPoint); while (endPoint != goThis.GridPos) { PassableObject endObject = grid.GetFromCell <PassableObject>(endPoint /*+Vector3.down*/); endPoint = endObject.PrevPos /*+Vector3.up*/; if (_points[0].y != endPoint.y) { Vector3 midPoint = _points[0].y < endPoint.y?_points[0]:endPoint; midPoint.y = _points[0].y < endPoint.y?endPoint.y:_points[0].y; _points.Insert(0, midPoint); } _points.Insert(0, endPoint); } return(true); }
virtual public bool CanObjectBePlacedAtPosition(IGridObject gridObject, GridPosition position) { GridPosition newPosition; foreach (GridPosition g in gridObject.Shape) { newPosition = position + g; if (newPosition.x < 0 || newPosition.x >= grid.GetLength(0)) { return(false); } if (newPosition.y < 0 || newPosition.y >= grid.GetLength(1)) { return(false); } if (grid[newPosition.x, newPosition.y] != null && grid[newPosition.x, newPosition.y] != gridObject) { return(false); } } return(true); }
public IEnumerator CalculateNextMoves(IGridObject target) { var targetTile = target.Tile; foreach (var enemyHolder in CurrentEnemies) { var enemy = enemyHolder.GridObject; var currentTile = enemy.Tile; var path = GridUtility.FindPath(currentTile, targetTile); enemy.MoveIntention = path?.First(); enemy.MoveIntention = enemy.MoveIntention ?? GridUtility.FindFallbackMove(currentTile); if (enemy.MoveIntention == null) { continue; } var targetHolder = enemyHolder.TileHolder.GridHolder.TileHolders[enemy.MoveIntention.Index]; GameManager.Instance.SelectionManager.AddToEnemyTarget(targetHolder.gameObject); yield return(enemyHolder.TurnTo(targetHolder, timeOnCalculateMove)); } GameManager.Instance.SelectionManager.DeselectAll(); }
public List <IGridObject> Conflict(IGridObject o, int x, int y) { var space = o.Space(); var dic = new Dictionary <Tuple <int, int>, IGridObject>(); for (int i = x; i != x + space.Item2.Item1; i++) { for (int j = y; j != y + space.Item2.Item2; j++) { if (space.Item1[i - x, j - y] && this.matrix[i, j].Item1 && !dic.ContainsKey(this.matrix[i, j].Item2.GridPosition())) { dic.Add(this.matrix[i, j].Item2.GridPosition(), this.matrix[i, j].Item2); } } } var result = new List <IGridObject>(); foreach (var i in dic) { result.Add(i.Value); } return(result); }
public string GridSdtName(IGridObject gridObject) { return GridObjectName(gridObject) + "SDT"; }
public virtual IGridObject GetNeighbor( IGridObject a, int direction ) { return null; }
public PassableObject(IGridObject gridObject) : base(gridObject) { }
private void CreateDefaultAction(IGridObject gridObject, string name, string mode, string condition,string codeEnable, List<ActionElement> newActions) { if (gridObject.Actions.FindAction(name) == null) { // Resolve "default" mode value from settings file. if (mode == ModesElement.InsertValue.Default) { SettingsActionElement settingsAction = Settings.StandardActions.FindAction(name); if (settingsAction != null && ((settingsAction.DefaultMode && !(gridObject is PromptElement)) || (settingsAction.PromptMode && (gridObject is PromptElement)))) mode = ModesElement.InsertValue.True; } if (mode == ModesElement.InsertValue.True) { ActionElement action = new ActionElement(name); action.Condition = condition; action.CodeEnable = codeEnable; newActions.Add(action); } } }
/** * Initialise the grid. */ virtual protected void Init() { initialised = true; grid = new IGridObject[gridSize, gridSize]; FillUnusableGrid (); gridObjects = new Dictionary<IGridObject, List<GridPosition>> (); }
public bool PagingButtons(IGridObject obj) { return (obj.GridType == GridTypeValue.Gxui ? true : DefaultPagingButtons); }
private void CreateDefaultActions(IGridObject gridObject) { if (gridObject.Modes != null) { List<ActionElement> newActions = new List<ActionElement>(); CreateDefaultAction(gridObject, StandardAction.Insert, gridObject.Modes.Insert, gridObject.Modes.InsertCondition,Settings.StandardActions.Insert.CodeEnable, newActions); CreateDefaultAction(gridObject, StandardAction.Display, gridObject.Modes.Display, gridObject.Modes.DisplayCondition, Settings.StandardActions.Display.CodeEnable, newActions); CreateDefaultAction(gridObject, StandardAction.Update, gridObject.Modes.Update, gridObject.Modes.UpdateCondition,Settings.StandardActions.Update.CodeEnable, newActions); CreateDefaultAction(gridObject, StandardAction.Delete, gridObject.Modes.Delete, gridObject.Modes.DeleteCondition,Settings.StandardActions.Delete.CodeEnable, newActions); CreateDefaultAction(gridObject, StandardAction.Export, gridObject.Modes.Export, gridObject.Modes.ExportCondition,Settings.StandardActions.Export.CodeEnable, newActions); gridObject.Actions.InsertRange(0, newActions); newActions = new List<ActionElement>(); CreateDefaultAction(gridObject, StandardAction.Legend, gridObject.Modes.Legend, "", Settings.StandardActions.Legend.CodeEnable, newActions); gridObject.Actions.AddRange(newActions); } }
private void AddGridFilter(IGridObject gridObject, Transaction trn, TransactionLevel level) { gridObject.Filter = new FilterElement(); AddGridFilterAttributes(gridObject.Filter, trn, level); AddGridFilterConditions(gridObject.Filter, trn, level); AddGridFilterDynamicFilters(gridObject.Filter, trn, level); }
private static string GridActions(IGridObject GridObject, bool actionsModes, bool geraBC, HPatternSettings settings) { StringBuilder sgrid = new StringBuilder(); if (actionsModes) { if (GridObject.Actions.MultiRowActions.Count > 0) { // Checkbox is first column. sgrid.Append(WebForm.GridVariable("Selected", null, "")); } foreach (ActionElement inGridAction in GridObject.Actions.GridActions) { // InGrid actions go next. if (geraBC && settings.StandardActions.FindAction(inGridAction.Name) != null) { Dictionary<String, Object> dict = new Dictionary<string, object>(); switch (inGridAction.Name) { case StandardAction.Insert: dict[Properties.HTMLSFLCOL.OnClickEvent] = "'DoInsert'"; break; case StandardAction.Update: dict[Properties.HTMLSFLCOL.OnClickEvent] = "'Atualiza'"; break; case StandardAction.Delete: dict[Properties.HTMLSFLCOL.OnClickEvent] = "'Apaga'"; break; case StandardAction.Display: dict[Properties.HTMLSFLCOL.OnClickEvent] = "'DoDisplay'"; break; } sgrid.Append(WebForm.GridVariable(inGridAction.ControlName(), null, String.Empty, true, null, dict)); } else { sgrid.Append(inGridAction.ToHtml()); } } } return sgrid.ToString(); }
public override IGridObject GetDiagonalNeighbor( IGridObject a, int direction ) { return HexUtilities.Add( a as Hex, diagonals[direction] as Hex ); }
private OrderElement AddOrder(IGridObject gridObject, string name) { OrderElement orderElement = new OrderElement(name); gridObject.Orders.Add(orderElement); return orderElement; }
private void AddGridOrders(IGridObject gridObject, Transaction trn, TransactionLevel level) { // Default order, by description attribute (if applicable). TransactionAttribute descAtt = level.DescriptionAttribute; if (descAtt != null && (descAtt.Attribute.Type != eDBType.BINARY && descAtt.Attribute.Type != eDBType.LONGVARCHAR) && (descAtt.Attribute.Class != AttributeClass.HORIZONTAL && descAtt.Attribute.Class != AttributeClass.VERTICAL)) { OrderElement orderElement = AddOrder(gridObject, descAtt.Attribute.ContextualTitleProperty); AddOrderAttribute(orderElement, descAtt, descAtt.Attribute.ContextualTitleProperty, true); } }
public string ExportProcedureName(IGridObject gridObject) { return ObjectName(this.Export, GridObjectName(gridObject)); }
public string GridSdtItemName(IGridObject gridObject) { string gridSdtName = GridSdtName(gridObject); return String.Format("{0}.{0}Item", gridSdtName); }