void Update() { if (_run) { turn_timer -= Time.deltaTime; if (turn_timer < 0 & last_sync_time * turn_timer > 0) { playing = playing == PLAY.ER1 ? PLAY.ER2 : PLAY.ER1; foreach (var c in character) { c.ac = acPerTurn; } playground.TurnChange(character); turn_timer = timePerTurn; last_sync_time = (int)Mathf.Ceil(timePerTurn); photonView.RPC("C_TurnChanged", PhotonTargets.AllViaServer, (int)playing, character[(int)playing].ac); } else { if (turn_timer <= last_sync_time) { photonView.RPC("C_Timer", PhotonTargets.AllViaServer, last_sync_time); last_sync_time--; } } } }
void InitClient(int gridX, int gridY, float offsetX, float offsetY) { Debug.Log("InitClient"); playground = Instantiate <VisualPlayground>(playground_prefab); playground.name = "Playground"; playground.Init(gridX, gridY, offsetX, offsetY); character = new VisualJack[2]; var l1 = Instantiate <VisualJack>(jack_prefab); l1.Init(PLAY.ER1, 0, 0, playground.Pos(0, 0)); Debug.Log("jack 1 pos = " + playground.Pos(0, 0)); l1.name = "Jack-1"; character[0] = l1; var l2 = Instantiate <VisualJack>(jack_prefab); l2.Init(PLAY.ER2, gridX - 1, 0, playground.Pos(gridX - 1, 0)); l2.name = "Jack-2"; character[1] = l2; iAm = PhotonNetwork.isMasterClient ? PLAY.ER1 : PLAY.ER2; input = FindObjectOfType <InputAdapter>(); input.onTap += OnTap; input.onDrag += OnDrag; ui = FindObjectOfType <UIAdapter>(); photonView.RPC("S_ClientInited", PhotonTargets.MasterClient, (int)iAm); }
public void Init(PLAY eR1, int x, int y, Vector3 pos) { player = eR1; this.x = x; this.y = y; transform.position = pos; }
public LogicJack(PLAY player, int x, int y) { this.player = player; this.x = x; this.y = y; matchScore = 0; points = 0; }
void S_ClientPrepared(int player) { Debug.Log("S_ClientPrepared"); ready[player] = true; if (ready[0] & ready[1]) { turn_timer = timePerTurn; last_sync_time = (int)Mathf.Ceil(timePerTurn); _run = true; playing = PLAY.ER1; photonView.RPC("C_TurnChanged", PhotonTargets.AllViaServer, (int)playing, character[(int)playing].ac); ready[0] = false; ready[1] = false; } }
void S_PlayerInput(int _player, int x, int y, int _treeSelected) { if (blockInput | !_run) { return; } PLAY player = (PLAY)_player; if (player != playing) { return; } TreeType treeSelected = (TreeType)_treeSelected; if (treeSelected != TreeType.None) { // plant a tree if (playground.PlantTree(character, _player, treeSelected, x, y)) { Debug.Log("SERVER Player plant tree OK x,y=" + new Int2(x, y)); StartCoroutine(corPlantTree(_player, x, y, _treeSelected, character[_player].ac, (int)Growth.Small)); } else { Debug.Log("SERVER Player plant tree FAILED"); } } else { // move or chop var op = character[_player].Opponent; if (op.x == x & op.y == y) { // chop player if (playground.ChopPlayer(character[_player], character[(int)op.player])) { Debug.Log("SERVER Player chop player OK"); if (op.hp > 0) { StartCoroutine(corChopPlayer(_player, (int)op.player, character[_player].ac)); } else { StartCoroutine(corMatchEnd(_player)); } } else { Debug.Log("SERVER Player chop player FAILED"); } } else { LogicTree t = playground.TreeAt(x, y); if (t == null) { //move if (playground.PlayerMove(character[_player], x, y)) { Debug.Log("SERVER Player move OK"); StartCoroutine(corPlayerMove(_player, x, y)); } else { Debug.Log("SERVER Player move FAILED"); } } else { // chop tree List <LogicTree> domino; if (playground.ChopTree(character[_player], x, y, out domino)) { Debug.Log("SERVER Player chop tree OK "); StartCoroutine(corChopTree(_player, x, y, domino)); } else { Debug.Log("SERVER Player chop tree FAILED"); } } } } }
void C_TurnChanged(int player, int ac) { ui.AC(ac); playing = (PLAY)player; }