public void ResetCell(IntVect2 cellKey) { PlayableCell cell = GetCell(cellKey); cell.Reset(); Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell); }
public void IncreaseCellBounty(IntVect2 cellKey, int amount) { PlayableCell cell = GetCell(cellKey); cell.Bounty += amount; Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell); }
public bool GetRandomCell(ref IntVect2 key) { List <Cell> availableCells = new List <Cell>(); foreach (List <Cell> row in _Cells) { foreach (Cell cell in row) { if (!cell.HasMission() && cell.IsFree()) { availableCells.Add(cell); } } } if (availableCells.Count < 1) { return(false); } else { key = availableCells.ElementAt(Random.Range(0, availableCells.Count)).Key; return(true); } }
public Mission(IntVect2 cellKey, string clientID, string targetID, float ttl) { CellKey = cellKey; ClientID = clientID; TargetID = targetID; TTL = ttl; }
public void CellProgressed(IntVect2 cellKey, float progress) { Cell cell = GetCell(cellKey); cell.Progress = progress; Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell); }
private void FreezeTarget(IntVect2 cellKey) { Cell cell = _GridModelController.GetCell(cellKey); if (cell.Target != null) { cell.Target.Freeze = true; } }
private void RegenerateSurroundingCells(Cell cell) { Debug.Log("RegenerateSurroundingCells"); IntVect2 cellKey = cell.Key; AddCellByDeviation(cell.Key, new IntVect2(-1, 0)); AddCellByDeviation(cell.Key, new IntVect2(1, 0)); AddCellByDeviation(cell.Key, new IntVect2(0, -1)); AddCellByDeviation(cell.Key, new IntVect2(0, 1)); }
private bool CellInPath(IntVect2 key, List <IntVect2> path) { foreach (IntVect2 cellKey in path) { if (cellKey == key) { return(true); } } return(false); }
public Mission GetMissionFromCellKey(IntVect2 key) { foreach (Mission mission in _Missions) { if (ShanghaiUtils.KeysMatch(mission.CellKey, key)) { return(mission); } } Debug.Log("ERROR, couldn't get mission from key " + key); return(null); }
private bool CheckPrevCellPositions(IntVect2 key, List <IntVect2> path) { if (CellInPath(key, path)) { Messenger.Broadcast(EVENT_MISSION_FAILED); return(false); } else if (path.Count > 1 && GetCell(path[path.Count - 1]).HasMission()) { return(false); } return(true); }
private void AddCellByDeviation(IntVect2 key, IntVect2 deviation) { IntVect2 newKey = new IntVect2(key.x + deviation.x, key.y + deviation.y); if (newKey.x >= 0 && newKey.x < ShanghaiConfig.Instance.GridSize && newKey.y >= 0 && newKey.y < ShanghaiConfig.Instance.GridSize) { Cell adjacentCell = _GridModelController.GetCell(newKey); if (adjacentCell.State == Cell.CellState.DEAD) { _GridModelController.ResetCell(adjacentCell); } } }
private void OnCellClicked(IntVect2 cellKey) { Cell cell = _Model.Grid.GetCell(cellKey); if (cell != null && cell.Source != null && cell.Source.PaintColour == ShanghaiUtils.PaintColour.NONE) { cell.Source.PaintColour = _Model.PaintColour; Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell); Messenger.Broadcast(EVENT_RESET_COLOUR_INTERVAL); } }
public bool ValidateCellInput(IntVect2 key, List <IntVect2> path) { PlayableCell cell = GetCell(key); if (CellIsConnected(key, path) && GetCell(key).IsFree() && CheckPrevCellPositions(key, path)) { UpdateCellPipeType(cell, path); Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell); return(true); } return(false); }
private bool CellIsConnected(IntVect2 key, List <IntVect2> path) { if (path.Count < 1) { // nothing yet } else { IntVect2 prevKey = GetCell(path[path.Count - 1]).Key; if ((Mathf.Abs(key.x - prevKey.x) == 1 && (key.y == prevKey.y)) || (Mathf.Abs(key.y - prevKey.y) == 1 && (key.x == prevKey.x))) { return(true); } } return(false); }
private void OnCellDragged(IntVect2 cellKey) { if (cellKey == _CurrentCell) { return; } _CurrentCell = cellKey; if (_Model.Grid.ValidateCellInput(cellKey, _Path)) { _Path.Add(cellKey); if (ShanghaiUtils.IsEndPoint(_Model.Grid.GetCell(cellKey))) { _Model.CanDraw = false; } } }
public bool GenerateSource() { IntVect2 cellKey = new IntVect2(0, 0); if (!_Model.Grid.GetRandomCell(ref cellKey)) { return(false); } float TTL = _Config.SourceWaitTime; Source source = new Source(cellKey, TTL, _Model.PaintColour); Messenger <Source> .Broadcast(EVENT_SOURCE_CREATED, source); return(true); }
public bool GenerateTarget() { IntVect2 cellKey = new IntVect2(0, 0); if (!_Model.Grid.GetRandomCell(ref cellKey)) { return(false); } ShanghaiUtils.PaintColour targetColour = ShanghaiUtils.GetRandomColour(_Model.AvailableColours); Debug.Log("targetColour: " + targetColour); float TTL = _Config.TargetWaitTime; Target target = new Target(cellKey, targetColour, TTL); Messenger <Target> .Broadcast(EVENT_TARGET_CREATED, target); return(true); }
public bool GenerateMission() { IntVect2 cellKey = new IntVect2(0, 0); if (!_Model.Grid.GetRandomCell(ref cellKey)) { return(false); } string targetID = _Model.Targets.ElementAt(Random.Range(0, _Model.Targets.Count)).Value.Key; string clientID = _Model.Clients.ElementAt(Random.Range(0, _Model.Clients.Count)).Value.Key; float TTL = _Config.MissionWaitTimeMedium + (Random.Range(0, _Config.MissionWaitTimeDeviance * 2)) - _Config.MissionWaitTimeDeviance; Mission mission = new Mission(cellKey, clientID, targetID, TTL); Messenger <Mission> .Broadcast(EVENT_MISSION_CREATED, mission); return(true); }
public bool ValidateCellInput(IntVect2 key, List <IntVect2> path) { Cell cell = GetCell(key); /* First point, can only be a valid source */ if (path.Count == 0 && cell.Source != null && cell.Source.PaintColour != ShanghaiUtils.PaintColour.NONE) { GameModel.Instance.PathColour = cell.Source.PaintColour; cell.Source.Locked = true; return(true); } else if (CellIsConnected(key, path) && CanDrawOnCell(GetCell(key), GetCell(path[0]))) { cell.HasPath = true; Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell); return(true); } return(false); }
public Source(IntVect2 cellKey, float ttl, ShanghaiUtils.PaintColour colour) { CellKey = cellKey; TTL = ttl; PaintColour = colour; }
public Cell GetCell(IntVect2 key) { return(_Cells[key.y][key.x]); }
public UnplayableCell(IntVect2 key) : base(key) { }
private void OnCellProgressed(IntVect2 cellKey, float progress) { _Grid.CellProgressed(cellKey, progress); }
public void ResetCell(IntVect2 cellKey) { Cell cell = GetCell(cellKey); ResetCell(cell); }
public ChanceCells(IntVect2 key) : base(key) { }
public static bool KeysMatch(IntVect2 k1, IntVect2 k2) { return(k1.x == k2.x && k1.y == k2.y); }
public GridCell(IntVect2 key) { Key = key; }
public Cell(IntVect2 key) { Key = key; }
public Target(IntVect2 cellKey, ShanghaiUtils.PaintColour colour, float ttl) { CellKey = cellKey; PaintColour = colour; TTL = ttl; }