void DestroyUnit( GameUnit unit ) { GamePlayerScene playerUnit = null; foreach (var player in Players) { foreach (var figure in player.Figures) { if (figure.Equals(unit)) { playerUnit = player; break; } } if (playerUnit != null) break; } if (playerUnit != null) playerUnit.Figures.Remove(unit); var cell = Grid.GetCellByObject<GameUnit>(unit); unit.gameObject.transform.parent = null; DestroyImmediate(unit.gameObject); }
public void AddGameUnit (GameUnit newUnit) { GameObject unitObject = GameObject.Instantiate (unitToken); unitObject.transform.parent = mapRoot; newUnit.UnitObject = unitObject; newUnit.UnitObject.SetActive (false); }
public void AddNewUnit (GameUnit unit) { unitList.Add (unit); //initiativeQueue token GameObject unitObject = GameObject.Instantiate (unit.UnitObject); UIEventListener.Get (unitObject).onClick = unit.OnClickAndShowMainMeun; unit.InitObject = unitObject; unitObject.transform.parent = this.initRoot; unitObject.transform.localScale = Vector3.one; unitObject.transform.localPosition = addPos; UISprite uiSprite = unitObject.GetComponent<UISprite> (); uiSprite.depth = startDepth - unitList.Count; uiSprite.height = TOKEN_SIZE; uiSprite.width = TOKEN_SIZE; TweenPosition tweenPos = unitObject.GetComponent<TweenPosition> (); tweenPos.from = addPos; float toY = baseTop - TOKEN_SIZE * unitList.Count; float maskHeight = 0.0f; if (toY < 0.0f) { maskHeight = -toY; toY = 0.0f; } tweenPos.to = new Vector3 (0, toY); tweenPos.ResetToBeginning (); tweenPos.PlayForward (); PlayInitToken (maskHeight, 1); }
private void CancelGameUnit(GameUnit gameUnit) { if (gameUnitsStarted.ContainsKey(gameUnit)) { gameUnitsStarted.Remove(gameUnit); } else { Log.Warning("Tryed to cancel a game unit that was not started: " + gameUnit); } Log.Debug("Cancelled pending unit for game unit:" + gameUnit); }
public void UpdateToken (GameUnit unit) { this.showUnit = unit; sprite.spriteName = unit.UnitObject.GetComponent<UISprite> ().spriteName; UIEventListener.Get (sprite.gameObject).onClick = showUnit.OnClickAndShowMainMeun; unitName.text = unit.Name; lv.text = unit.Template.Lv.ToString (); speed.text = unit.Template.Speed.ToString (); hp.text = unit.Hp.ToString () + "/" + unit.Template.Hp.ToString (); ac.text = unit.Template.Ac.ToString (); fortitude.text = unit.Template.Fortitude.ToString (); reflex.text = unit.Template.Reflex.ToString (); will.text = unit.Template.Will.ToString (); }
void Awake() { if (enabled && NetworkManager.IsMine(this)) { trans = transform; unit = GetComponent<GameUnit>(); ship = GetComponent<Spaceship>(); shield = GetComponentInChildren<DamageShield>(); ship.name = "Player"; } else { Destroy(this); } }
/// <summary> /// Find the unit that's easiest to aim at given the specified direction. /// </summary> public static GameUnit Find(GameUnit myUnit, Vector3 dir, float maxRange, float maxAngle, UnitType [] enemyType) { GameUnit bestUnit = null; if (myUnit != null) { float bestValue = 0f; Vector3 pos = myUnit.transform.position; List<GameUnit> list = new List<GameUnit>(); foreach(UnitType type in enemyType) { list.AddRange(mAllListDict[type]); } foreach (GameUnit unit in list) { if (unit == myUnit || unit == null || unit.mTrans == null) continue; // If the unit is too far, move on to the next Vector3 unitDir = unit.mTrans.position - pos; float distance = unitDir.magnitude; if (distance > maxRange || distance < 0.01f) continue; // Normalize the distance and determine the dot product if (distance != 0f) unitDir *= 1.0f / distance; // Calculate the angle float angle = Vector3.Angle(dir, unitDir); // The angle must be within the sensor threshold if (angle < maxAngle) { // Calculate the value of this target float val = (maxRange - distance) / maxRange * (1f - angle / maxAngle); if (val > bestValue) { bestValue = val; bestUnit = unit; } } } } return bestUnit; }
public void Init (EncounterTemplate encounterTemplate) { this.encounterTemplate = encounterTemplate; //init unit unitList = new List<GameUnit> (); for (int i = 0; i < this.encounterTemplate.UnitList.Count; i++) { EncounterUnitData data = this.encounterTemplate.UnitList [i]; //map token GameUnit unit = new GameUnit (); unit.Template = GameWorld.Instance.UnitTemplateManager.GetTemplateById (data.TemplateId); GameWorld.Instance.gameMap.AddGameUnit (unit); unit.X = data.Pos.X; unit.Y = data.Pos.Y; unit.UnitSide = data.UnitSide; unitList.Add (unit); } GameWorld.Instance.message.ShowMessage ("战斗开始", delegate () { GameWorld.Instance.message.ShowMessage ("投先攻", RollInitiative); }); }
private void EmitUnitChanged(GameUnit gameUnit, TimelineNode unit, Time time) { if (UnitChanged != null) UnitChanged(gameUnit, unit, time); }
public override void DoEffect(GameUnit caster, Vector3 target, LayerMask canHit, EventCaster eventCaster) { eventCaster.transform.Translate(localTranslate, Space.Self); }
private static void SetTarget(GameUnit unit) { TargetSelector.SetTarget((Obj_AI_Hero)unit.Unit); }
private void EmitGameUnitEvent(GameUnit gameUnit, GameUnitEventType eType) { if (GameUnitEvent != null) GameUnitEvent(gameUnit, eType); }
private void RemoveGameUnit(GameUnit gameUnit, bool delete) { phasesbox.Remove(dict[gameUnit]); dict[gameUnit].Destroy(); dict.Remove(gameUnit); if (delete) gameUnits.Remove(gameUnit); }
private void AddGameUnit(GameUnit gameUnit, bool append) { HBox hbox; Label label; Button button; Log.Debug("Adding new game unit" + gameUnit); label1.Hide(); outerbox.Visible = true; if (append) gameUnits.Add(gameUnit); /* Create widget that display the game unit name and a button to remove it */ hbox = new HBox(); label = new Label(gameUnit.Name); label.Justify = Justification.Left; button = new Button("gtk-delete"); button.Clicked += (sender, e) => {RemoveGameUnitAndChildren(gameUnit);}; dict.Add(gameUnit, hbox); /* Pack everything */ hbox.PackStart(label, false, false, (uint)((gameUnits.GameUnitDepth(gameUnit) * 10) + 10)); hbox.PackEnd(button, false, false, 0); label.Show(); button.Show(); hbox.Show(); phasesbox.PackStart(hbox, true, false, 0); }
// Use this for initialization void Awake() { sprite = GetComponent <SpriteComponent>(); player = GetComponent <Player>(); gameUnit = GetComponent <GameUnit>(); }
public void registerUnit(GameUnit u) { units.Add(u); }
public void Setup(GameUnit oldhome) { home = oldhome; }
public void initUnits() { GameBattleStage stage = GameBattleManager.instance.ActiveBattleStage; units = new GameBattleUnit[stage.Man.Length]; for (int i = 0; i < stage.Man.Length; i++) { GameUnit unit = GameUnitData.instance.getData(stage.Man[i].UnitBase.UnitID); string path = "Prefab/Sprite/man" + GameDefine.getString3(unit.Sprite) + "/"; path += (GameDefine.getString3(unit.Sprite) + "man"); GameObject obj = Instantiate <GameObject>(Resources.Load <GameObject>(path)); GameAnimation ani = obj.GetComponent <GameAnimation>(); obj.name = "man" + GameDefine.getString3(unit.Sprite) + " " + i + " " + stage.Man[i].UnitBase.UnitID; Transform trans = obj.transform; trans.SetParent(unitTransform); trans.localScale = new Vector3(1.0f, 1.0f, 1.0f); GameBattleMovement movement = obj.AddComponent <GameBattleMovement>(); GameBattleUnit battleUnit = obj.AddComponent <GameBattleUnit>(); battleUnit.init(unit, stage.Man[i].clone()); if (battleUnit.UnitID < GameDefine.MAX_USER) { battleUnit.setUnitBase(GameUserData.instance.getUnitBase(battleUnit.UnitID)); } battleUnit.updateUnitData(); battleUnit.initHPMP(); battleUnit.clearMove(); if (battleUnit.IsUser) { addUser(battleUnit); } else if (battleUnit.IsEnemy) { addEnemy(battleUnit); } else if (battleUnit.IsNpc) { addNpc(battleUnit); } units[i] = battleUnit; if (stage.XY.Length <= i) { } else { GameBattleXY xy = stage.XY[i]; movement.setPos(xy.X, xy.Y); } } }
public override void DoAction(GameUnit unit, AI_State state) { unit.spriteC.faceDirection(unit.spriteC.moveRight); }
public override void eventRotation(GameUnit caster, Vector3 target, Transform ev) { Vector3 inversePosition = (ev.position - caster.spriteC.shotSpawn.position) + ev.position; ev.LookAt(inversePosition, Vector3.up); }
public void SetUnit(GameUnit unit, Vector2Int pos) { tiles[pos.x, pos.y].unit = unit; }
public void DoAttackAction (GameUnit target) { GameWorld.Instance.gameMap.HideAttackArea (); GameWorld.Instance.Encounter.HideAttackTarget (); GameWorld.Instance.actionMenu.Hide (); GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]匕首攻击:[00FF00]D20+5[-]", Name), delegate() { GameWorld.Instance.gameMap.LookAtPos (new VectorInt2 (target.X, target.Y), delegate() { int oldX = X; int oldY = Y; X = target.X; Y = target.Y; int ab = Dice.Roll (DiceType.D20, 5); GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]匕首攻击:[00FF00]{1}+5={2}[-]", Name, ab - 5, ab), delegate() { if (ab >= target.template.Ac) { GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]的AC:[00FF00]{1}vs{2}[-]=>[00FF00]hit[-]", target.Name, target.template.Ac, ab), delegate() { GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]匕首伤害:[00FF00]D4+3[-]", Name), delegate() { int damage = Dice.Roll (DiceType.D4, 3); GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]匕首伤害:[00FF00]{1}+3={2}[-]", Name, damage - 3, damage), delegate() { if (target.TakeDamage (damage) == true) { //show damage and dead target.ShowDamage (damage, target.ShowDead); } else { //show damage target.ShowDamage (damage, null); } AttackFinish (oldX, oldY); }); }); }); } else { GameWorld.Instance.message.ShowMessage (string.Format ("[0000FF]{0}[-]的AC:[00FF00]{1}vs{2}[-]=>[FF0000]miss[-]", target.Name, target.template.Ac, ab), delegate() { AttackFinish (oldX, oldY); }); } }); }); }); }
public abstract void Activate(GameUnit source, List <GameUnit> targets);
public static void RemoveEntFromGroup(GameUnit ent) { if (GroupList.ContainsKey(ent.Group) && GroupList[ent.Group].Contains(ent)) GroupList[ent.Group].Remove(ent); }
public Skill(GameUnit owner) { m_owner = owner; }
public void Start() { this.enemiesInRange = new List<GameUnit>(); this.removeList = new List<GameUnit>(); this.exitedList = new List<GameUnit>(); SphereCollider collider = this.GetComponent<SphereCollider>(); if (collider != null) { this.radius = collider.radius; } this.sphereColliderRigidBody = this.GetComponent<Rigidbody>(); this.parent = this.GetComponentInParent<GameUnit>(); if (parent == null) { Debug.LogError("There's something wrong with this parent GameUnit object."); } }
private void EmitUnitSelected(GameUnit gameUnit, TimelineNode unit) { if (UnitSelected != null) UnitSelected(gameUnit, unit); }
private void RemoveGameUnitAndChildren(GameUnit gameUnit) { int depth = gameUnits.GameUnitDepth(gameUnit); foreach (var g in gameUnits.GetRange(depth, gameUnits.Count - depth)) RemoveGameUnit(g, true); }
public void UnitOnClick (GameUnit clickUnit) { if (attacker != null) { if (attacker.IsEnemy (clickUnit) == true) { if (Mathf.Abs (clickUnit.X - attacker.X) <= range && Mathf.Abs (clickUnit.Y - attacker.Y) <= range) { attacker.DoAttackAction (clickUnit); } } } }
public GameUnitWidget(GameUnit gameUnit) { AddGameUnitButton(); GameUnit = gameUnit; CurrentTime = new Time {MSeconds = 0}; }
public void HideAttackTarget () { this.attacker = null; for (int i = 0; i < unitList.Count; i++) { unitList [i].HideAttackedState (); } }
private static Position WorldToScreen(GameUnit unit) { return unit.pos; }
public bool selectPath(int x, int y, GameUnit unit) { int px, py; int safecounter = 0; this.unit = unit; if (cost [x, y] > 0) { movementPattern.Clear(); px = x; py = y; while (px != originx || py != originy) { movementPattern.Insert(0, new Vector2(px, py)); // string pathLog = "PathLog: [" + safecounter + "] x=" + px + ", y=" + py +" d=" + direction[px,py]; // Debug.Log(pathLog); switch (direction [px, py]) { case OriginDirection.N: py++; break; case OriginDirection.S: py--; break; case OriginDirection.E: px++; break; case OriginDirection.W: px--; break; } safecounter++; if (safecounter > 100) { Debug.Log("PathIssue"); break; } } } else if (cost [x, y] < 0 && movementPattern.Count > 0) // PathBacktracing { PathShow pathRenderer; Vector2 coord = (Vector2)movementPattern[movementPattern.Count - 1]; px = (int)coord.x; py = (int)coord.y; while (movementPattern.Count > 1 && (px != x || py != y)) { pathRenderer = PlayMap.Grid.getTileSpec(px, py).PathRenderer; pathRenderer.HidePath(); movementPattern.RemoveAt(movementPattern.Count - 1); coord = (Vector2)movementPattern[movementPattern.Count - 1]; px = (int)coord.x; py = (int)coord.y; } pathRenderer = PlayMap.Grid.getTileSpec(px, py).PathRenderer; pathRenderer.Type = PathShow.PathType.Target; } if (cost [x, y] != 0) { reMapMovement(); return(true); } else { return(false); } }
private void EmitUnitAdded(GameUnit gameUnit, int frame) { if (UnitAdded != null) UnitAdded(gameUnit, frame); }
public bool IsEnemy (GameUnit targetUnit) { return UnitSide != targetUnit.UnitSide; }
private void EmitUnitDeleted(GameUnit gameUnit, List<TimelineNode> units) { if (UnitDeleted != null) UnitDeleted(gameUnit, units); }
public override bool Condition(GameUnit unit) { return(Time.time > unit.stateC.nextAbility); }
public void buildUnit(int slotIndex, IUnitInfo unit) { if (unit == null) return; TargetedAction upgradeAction = null; //Begin by destroying the old unit if( units[slotIndex] != null ) { upgradeAction = units[slotIndex].originCard.upgrader; if( upgradeAction != null ) ui.triggerFlash( new int[]{slotIndex} ); destroyUnit( slotIndex ); //If destroyed unit has an UPGRADE, it will trigger the UI flash as it's being destroyed } //Create the actual unit enqueueAction (delegate(IGameplay g) { GameUnit u = new GameUnit (); u.energy = unit.getEnergy (); u.originCard = unit.getOriginCard (); u.name = unit.getName (); //Add attributes attached to this card foreach (string attr in unit.getAttributes()) u.addAttribute (attr, (int)unit.getAttrValue (attr)); //Register triggers attached to this card foreach( Trigger t in unit.getOriginCard().getTriggers() ) registerTrigger( t, slotIndex ); units [slotIndex] = u; ui.onCreateUnit (slotIndex, u); }); //Do the UPGRADE trigger if( upgradeAction != null ) enqueueAction ( delegate(IGameplay g) { upgradeAction(g, slotIndex); }); //Supply if (getAttributeTotal (BoardManager.supplyAttr) > 0) enqueueAction( delegate(IGameplay g) { List<int> supplySlots = new List<int>(BoardManager.MAX_UNITS); int supplyTotal = 0; for( int i = 0; i < BoardManager.MAX_UNITS; ++i ) { if( i == slotIndex || units[i] == null ) continue; int? supplyValue = units[i].getAttrValue(supplyAttr); if( supplyValue != null && supplyValue != 0 ) { supplySlots.Add(i); supplyTotal += (int)supplyValue; } } if( supplySlots.Count > 0 ) g.modifyEnergy(slotIndex, supplyTotal ); ui.triggerFlash( supplySlots.ToArray() ); }); //buildup if( getAttributeTotal(BoardManager.buildupAttr) > 0 ) enqueueAction( delegate(IGameplay g) { for( int i = 0; i < BoardManager.MAX_UNITS; ++i ) { if( i == slotIndex || units[i] == null ) continue; int? buildupValue = units[i].getAttrValue(buildupAttr); if( buildupValue != null && buildupValue != 0 ) g.modifyEnergy( i, (int)buildupValue ); } }); //CreateUnit triggers (other than supply/buildup) foreach (Trigger t in allTriggers) if (t is CreateUnitTrigger) { CreateUnitTrigger captured = t as CreateUnitTrigger; if( captured.test != null && !captured.test(this, t.attachedSlot, slotIndex) ) continue; enqueueAction ( delegate(IGameplay g) { byte flags = captured.run( g, captured.attachedSlot, slotIndex); if( (flags & Trigger.FLASH) != 0 ) ui.triggerFlash( captured.attachedSlot ); if( (flags & Trigger.REMOVE) != 0 ) allTriggers.Remove( captured ); }); } }
private void DestroyProjectile(GameUnit destroyer) { DestroyObject(gameObject); if (OnDestroy != null) OnDestroy(destroyer); }
public void ShowAttackTarget (GameUnit attacker, int range) { this.attacker = attacker; this.range = range; for (int i = 0; i < unitList.Count; i++) { GameUnit temp = unitList [i]; if (attacker.IsEnemy (temp) == true) { if (Mathf.Abs (temp.X - attacker.X) <= range && Mathf.Abs (temp.Y - attacker.Y) <= range) { temp.ShowAttactedState (); } } } }
void Start() { gu = gameObject.GetComponent<GameUnit>(); }
void Start() { mTrans = transform; mMyUnit = GameUnit.Find(transform); if( mMyUnit == null ) Debug.LogError("Cannot find GameUnit of " + transform.name); }
public override void DoAction(GameUnit unit, AI_State state) { unit.agent.avoidancePriority = unit.preset.agentPriority; }