void ProcessMyCommand() { for (int i = 0; i < commands.Count; i++) { Command c1 = commands[i]; if (c1 == null) { continue; } if (c1.processed) { continue; } if (c1 is GameSetCmd) { GameSetCmd c = (GameSetCmd)c1; openResultScene(c.isHostWin); } if (c1 is UnitMovedCmd) { UnitMovedCmd c = (UnitMovedCmd)c1; var basicUnit = GetBasicUnit(c.uuid); //Debug.Log(c.vx); if (basicUnit != null && !basicUnit.MovementLocked && !basicUnit.Locked) // lockdown and waittime check { Unit u = GetUnit(c.uuid); u.vx = c.vx; u.vz = c.vz; //schin Remove "ready to roll" emotion when ready. // this doesn't check if it's really moved for client basicUnit.ExpireEmotion(EmotionType.CD_READY); // Tinaxd update CountdownUI (Host only) // Generate a UnitTimerCommand if (isClient == 0) { UnitTimerCmd utc = new UnitTimerCmd(); utc.penalty = basicUnit.WaitTimePenaltyTime; utc.timerType = UnitTimerCmd.MOVED; utc.uuid = c.uuid; unitTimerRequests.Add(utc); commands.Add(utc); } } else { } c.processed = true; } if (c1 is UnitUpdateCmd) { UnitUpdateCmd c = (UnitUpdateCmd)c1; //Debug.Log(c.vx); if (isClient > 0) { //TODO if units.isDeadあり //UnitDied() units = c.units; } c.processed = true; c.sent = true; } if (c1 is UnitTimerCmd) { UnitTimerCmd c = (UnitTimerCmd)c1; switch (c.timerType) { case 0: // MOVED var basicUnit = GetBasicUnit(c.uuid); if (basicUnit != null) { basicUnit.MarkMoved(); } // Lockdown ends foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (bu.Owned != basicUnit.Owned) { bu.MovementLocked = false; } } break; case 1: // HOST LOCKDOWN foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (isClient > 0) { if (bu.Owned) { bu.MovementLocked = true; } else { bu.MarkLockdown(); } } else { if (bu.Owned) { bu.MarkLockdown(); } else { bu.MovementLocked = true; } } } break; case 2: // CLIENT LOCKDOWN foreach (var instance in instances) { var bu = instance.basicUnit; if (bu == null) { continue; } if (isClient > 0) { if (bu.Owned) { bu.MarkLockdown(); } else { bu.MovementLocked = true; } } else { if (bu.Owned) { bu.MovementLocked = true; } else { bu.MarkLockdown(); } } } break; } //TODO if c is GameSetCmd //SceneManager.LoadScene("Result"); //clientBattleScene, isHostWin = GameSetCmd.isHostWin if (isClient > 0 && (!AutoPlay.isOffline)) { c.processed = true; } } if (c1 is NewUnitCmd) { //Debug.Log(GetUnit(((NewUnitCmd)c1).fromUnitId).owner); NewUnitCmd c = (NewUnitCmd)c1; switch (c.unitType) { case 2: // Arrow { Unit u = GetUnit(c.fromUnitId); if (u == null) { break; } if (u.projectileReload <= 0) { u.projectileReload = 7; CreateArrow(GetUnit(c.fromUnitId), c.velocity); } } break; case 3: // Fireball { var u = GetUnit(c.fromUnitId); if (u.MP > 25) { u.MP -= 25; CreateFireball(u, c.velocity); } } break; } c.processed = true; } if (c1 is HealingBuffRequestCmd) { var c = (HealingBuffRequestCmd)c1; if (isClient == 0) { var requestor = GetUnit(c.RequestorId); var target = GetUnit(c.TargetId); if (PhysicsSimulator.UnitDistance1(requestor, target) < HealingBuffMaxDistance) { target.buff |= BuffFlag.BUFF_HEALING; } c.processed = true; } //GetBasicUnit(c.RequestorId).DragMode = DragType.NORMAL; //UnityEngine.EventSystems.ExecuteEvents.Execute<IDragAndFireEventHandler>(this.gameObject, null, (x, y) => x.TurnOnDrag()); } } List <Command> remains = new List <Command>(); for (int i = 0; i < commands.Count; i++) { if (commands[i].sent) { continue; } remains.Add(commands[i]); } commands = remains; }
// Update is called once per frame void Update() { if (!DragEnabled) { grabbing = false; target = null; targetScript = null; return; } if (target == null) { grabbing = false; target = null; targetScript = null; } if (target != null && Input.GetKeyDown(KeyCode.Escape)) // Tinaxd Press Esc to cancel dragging { target.GetComponent <BasicUnit>().NotifyDragEnd(); grabbing = false; target = null; targetScript = null; return; } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Unit") { target = hit.transform.gameObject; targetScript = hit.transform.GetComponent <UnitInfoTag>(); grabbing = true; targetPlane = new Plane(Vector3.up, target.transform.position); float enter = 0; targetPlane.Raycast(ray, out enter); localOrigin = ray.GetPoint(enter); targetUnit = simulator.GetUnit(targetScript.uuid); if (targetUnit.owner != simulator.isClient)//0:host 1:client { grabbing = false; target = null; targetScript = null; } else // Tinaxd show DragUI { target.GetComponent <BasicUnit>().NotifyDragStart(); } } } } if (Input.GetMouseButtonUp(0)) { if (grabbing) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float enter = 0; targetPlane.Raycast(ray, out enter); // Debug.Log(localOrigin - ray.GetPoint(enter)); Vector3 vel = localOrigin - ray.GetPoint(enter); vel *= 2; DragType dt = DragType.NORMAL; vel = GetVelocity(vel); switch (dt) { case DragType.NORMAL: UnitMovedCmd c = new UnitMovedCmd(); c.sent = false; c.vx = vel.x; c.vz = vel.z; c.uuid = targetUnit.uuid; c.owner = simulator.isClient; simulator.commands.Add(c); break; case DragType.ARCHER: //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL; NewUnitCmd cmd = new NewUnitCmd { fromUnitId = target.GetComponent <BasicUnit>().unit.uuid, velocity = new Vector3(vel.x * 3, 0, vel.z * 3), unitType = 2, // Unit type Arrow }; simulator.commands.Add(cmd); break; case DragType.FIREBALL: //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL; NewUnitCmd cmd2 = new NewUnitCmd { fromUnitId = target.GetComponent <BasicUnit>().unit.uuid, velocity = new Vector3(vel.x * 3, 0, vel.z * 3), unitType = 3, // Unit type Fireball }; simulator.commands.Add(cmd2); break; } //targetScript.rg.AddForce(vel, ForceMode.VelocityChange); /* * CommandData c = new CommandData(); * c.sent = false; * c.when = manager.elapsedTime; * c.vx = vel.x; * c.vz = vel.z; * c.x = targetScript.transform.position.x; * c.z = targetScript.transform.position.z; * * targetScript.command = c;*/ grabbing = false; target.GetComponent <BasicUnit>().NotifyDragEnd(); // Tinaxd disable DragUI } } ballisticsSimulator.lr.enabled = grabbing; // Tinaxd update DragUI if (grabbing) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var basicUnit = target.GetComponent <BasicUnit>(); float enter = 0; targetPlane.Raycast(ray, out enter); var point = ray.GetPoint(enter); Vector3 diff = -point + localOrigin; diff *= 2; diff = GetVelocity(diff); ballisticsSimulator.UpdateTrails(target.transform.position, diff); basicUnit.NotifyDragUpdate(point); } }
private void Update() { queue += Time.deltaTime; if (queue > 5) { queue = 0; } List <Unit> myUnit = new List <Unit>(); List <Unit> units = sim.units; List <Unit> enemies = new List <Unit>(); for (int i = 0; i < units.Count; i++) { if (units[i].owner == 0) { enemies.Add(units[i]); } if (units[i].owner == 1) { myUnit.Add(units[i]); } } List <bool> occupied = new List <bool>(); for (int i = 0; i < units.Count; i++) { occupied.Add(false); } for (int i = 0; i < myUnit.Count; i++) { Unit u = myUnit[i]; if (u.type != UnitType.TYPE_CHESS) { continue; } Unit target = FindNearest(u.GetPosition(), enemies); if (i % 5 != Mathf.Floor(queue)) { continue; } if (target == null) { break; } if (u.GetVelocity().magnitude > 0.1f) { continue; } enemies.Remove(target); Vector3 vel = target.GetPosition() - u.GetPosition(); vel = vel.normalized * 2; UnitMovedCmd c = new UnitMovedCmd(); c.sent = false; c.vx = vel.x; c.vz = vel.z; c.uuid = u.uuid; c.owner = 0; sim.commands.Add(c); } for (int i = 0; i < myUnit.Count; i++) { if (i % 5 != Mathf.Floor(queue)) { continue; } Unit u = myUnit[i]; if (u.type == UnitType.TYPE_CHESS) { continue; } Unit target = FindNearest(u.GetPosition(), enemies); if (target == null) { break; } enemies.Remove(target); Vector3 vel = target.GetPosition() - u.GetPosition(); vel = vel.normalized * 1; UnitMovedCmd c = new UnitMovedCmd(); c.sent = false; c.vx = vel.x; c.vz = vel.z; c.uuid = u.uuid; c.owner = 1; sim.commands.Add(c); } }