예제 #1
0
    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);
    }
예제 #2
0
파일: Map.cs 프로젝트: kamiya-tips/DND4
	public void AddGameUnit (GameUnit newUnit)
	{
		GameObject unitObject = GameObject.Instantiate (unitToken);
		unitObject.transform.parent = mapRoot;
		newUnit.UnitObject = unitObject;
		newUnit.UnitObject.SetActive (false);
	}
예제 #3
0
	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);
	}
예제 #4
0
 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);
 }
예제 #5
0
	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 ();
	}
예제 #6
0
파일: Player.cs 프로젝트: Greigy/TheGame
    void Awake()
    {
        if (enabled && NetworkManager.IsMine(this))
        {
            trans	= transform;
            unit	= GetComponent<GameUnit>();
            ship	= GetComponent<Spaceship>();
            shield	= GetComponentInChildren<DamageShield>();

            ship.name = "Player";
        }
        else
        {
            Destroy(this);
        }
    }
예제 #7
0
    /// <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;
    }
예제 #8
0
	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);
		});
	}
예제 #9
0
 private void EmitUnitChanged(GameUnit gameUnit, TimelineNode unit, Time time)
 {
     if (UnitChanged != null)
         UnitChanged(gameUnit, unit, time);
 }
예제 #10
0
 public override void DoEffect(GameUnit caster, Vector3 target, LayerMask canHit, EventCaster eventCaster)
 {
     eventCaster.transform.Translate(localTranslate, Space.Self);
 }
예제 #11
0
 private static void SetTarget(GameUnit unit)
 {
     TargetSelector.SetTarget((Obj_AI_Hero)unit.Unit);
 }
예제 #12
0
 private void EmitGameUnitEvent(GameUnit gameUnit, GameUnitEventType eType)
 {
     if (GameUnitEvent != null)
         GameUnitEvent(gameUnit, eType);
 }
예제 #13
0
 private void RemoveGameUnit(GameUnit gameUnit, bool delete)
 {
     phasesbox.Remove(dict[gameUnit]);
     dict[gameUnit].Destroy();
     dict.Remove(gameUnit);
     if (delete)
         gameUnits.Remove(gameUnit);
 }
예제 #14
0
        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);
        }
예제 #15
0
 // Use this for initialization
 void Awake()
 {
     sprite   = GetComponent <SpriteComponent>();
     player   = GetComponent <Player>();
     gameUnit = GetComponent <GameUnit>();
 }
예제 #16
0
 public void registerUnit(GameUnit u)
 {
     units.Add(u);
 }
예제 #17
0
 public void Setup(GameUnit oldhome)
 {
     home = oldhome;
 }
예제 #18
0
    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);
    }
예제 #21
0
 public void SetUnit(GameUnit unit, Vector2Int pos)
 {
     tiles[pos.x, pos.y].unit = unit;
 }
예제 #22
0
	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);
						});
					}
				});
			});
		});
	}
예제 #23
0
 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);
 }
예제 #25
0
 public Skill(GameUnit owner)
 {
     m_owner = owner;
 }
예제 #26
0
 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.");
     }
 }
예제 #27
0
 private void EmitUnitSelected(GameUnit gameUnit, TimelineNode unit)
 {
     if (UnitSelected != null)
         UnitSelected(gameUnit, unit);
 }
예제 #28
0
        private void RemoveGameUnitAndChildren(GameUnit gameUnit)
        {
            int depth = gameUnits.GameUnitDepth(gameUnit);

            foreach (var g in gameUnits.GetRange(depth, gameUnits.Count - depth))
                RemoveGameUnit(g, true);
        }
예제 #29
0
	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);
				}
			}
		}
	}
예제 #30
0
 public GameUnitWidget(GameUnit gameUnit)
 {
     AddGameUnitButton();
     GameUnit = gameUnit;
     CurrentTime = new Time {MSeconds = 0};
 }
예제 #31
0
	public void HideAttackTarget ()
	{
		this.attacker = null;
		for (int i = 0; i < unitList.Count; i++) {
			unitList [i].HideAttackedState ();
		}
	}
예제 #32
0
 private static Position WorldToScreen(GameUnit unit)
 {
     return unit.pos;
 }
예제 #33
0
    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);
        }
    }
예제 #34
0
 private void EmitUnitAdded(GameUnit gameUnit, int frame)
 {
     if (UnitAdded != null)
         UnitAdded(gameUnit, frame);
 }
예제 #35
0
	public bool IsEnemy (GameUnit targetUnit)
	{
		return UnitSide != targetUnit.UnitSide;
	}
예제 #36
0
 private void EmitUnitDeleted(GameUnit gameUnit, List<TimelineNode> units)
 {
     if (UnitDeleted != null)
         UnitDeleted(gameUnit, units);
 }
예제 #37
0
 public override bool Condition(GameUnit unit)
 {
     return(Time.time > unit.stateC.nextAbility);
 }
예제 #38
0
    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 );
            });
        }
    }
예제 #39
0
 private void DestroyProjectile(GameUnit destroyer)
 {
     DestroyObject(gameObject);
     if (OnDestroy != null)
         OnDestroy(destroyer);
 }
예제 #40
0
	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 ();
				}
			}
		}
	}
예제 #41
0
 void Start()
 {
     gu = gameObject.GetComponent<GameUnit>();
 }
예제 #42
0
 void Start()
 {
     mTrans = transform;
     mMyUnit = GameUnit.Find(transform);
     if( mMyUnit == null ) Debug.LogError("Cannot find GameUnit of " + transform.name);
 }
예제 #43
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     unit.agent.avoidancePriority = unit.preset.agentPriority;
 }