コード例 #1
0
 public UnitTakesDamageEvent(UnitEntity dmgtaker, UnitEntity dmgdealer, int Damage)
 {
     // TODO: Complete member initialization
     this.dmgtaker = dmgtaker;
     this.dmgdealer = dmgdealer;
     this.Damage = Damage;
 }
コード例 #2
0
 public BeginMoveEvent(UnitEntity u, Point from, Point to, int dur)
 {
     this.unit = u;
     this.from = from;
     this.to = to;
     this.duration = dur;
 }
コード例 #3
0
 public DeclareMoveAttackUnitCommand(GameObject unit, UnitEntity unitEntity)
 {
     this.unit = unit;
     this.unitEntity = unitEntity;
     this.originalColor = this.unit.renderer.material.color;
     this.unit.renderer.material.color = Color.red;
     this.lastpos = (TilePosition)unitEntity.Position;
 }
コード例 #4
0
        public Transform CreateUnit(UnitEntity unitEnt, TilePosition posinfo)
        {
            var pos = posinfo.Point;
            Quaternion ur = UnitTemplate.rotation;
            Quaternion rot = new Quaternion(ur.x + 0.14f, ur.y, ur.z, ur.w);
            Vector3 unitvec = ConvertUnitPos(pos);
            var unitobj = (Transform)Instantiate(UnitTemplate, unitvec, rot);
            var info = unitobj.gameObject.AddComponent<UnitInformation>();

            unitobj.gameObject.AddComponent<UnitViewHandler>();
            unitobj.gameObject.AddComponent<UnitControllerHandler>();

            info.SetEntity(unitEnt);
            UnitGraphics graphic = (UnitGraphics)GraphicFactory.ConstuctGraphic(unitEnt.getUnitType());
            graphic.SetUnitObj(unitobj.gameObject);
            graphic.Initialize(this);
            info.SetGraphics(graphic);

            var viewhandler = unitobj.gameObject.GetComponent<UnitViewHandler>();
            viewhandler.Factory = this;
            viewhandler.HealthBar = (Transform)Instantiate(this.HealthBarTemplate);
            viewhandler.HealthBar.GetComponent<HealthbarView>().SetPosition(pos);
            this.gameobjLookUp.Add(unitEnt,unitobj.gameObject);
            return unitobj;
        }
コード例 #5
0
 public AttackUnitAction(UnitEntity target)
 {
     this.Target = target;
 }
コード例 #6
0
 public DealDamageToUnitAction(UnitEntity target, int dmg)
 {
     this.Target = target;
     this.Damage = dmg;
 }
コード例 #7
0
 public DeclareMoveAttackCommand(Player player, Path<TileWorld, TilePosition> movePath, UnitEntity Attack)
     : this(player, movePath)
 {
     this.attackUnit = Attack;
 }
コード例 #8
0
 public EndMoveEvent(UnitEntity u, Point from, Point to)
 {
     this.unit = u;
     this.from = from;
     this.to = to;
 }
コード例 #9
0
        public override void Update()
        {
            GameObject[] gobjs = this.GuiController.GetGameObjectsOnMouse();
            GameObject firstter = gobjs.FirstOrDefault(go => go.gameObject.GetComponent<TerrainInformation>() != null);
            UnitEntity attackUnit = null;
            if (firstter != null)
            {
                TerrainInformation terinfo = firstter.GetComponent<TerrainInformation>();
                TilePosition tilepos = (TilePosition)terinfo.Terrain.Position;

                if (tilepos != null && (mousePoint != tilepos.Point && lastpos.Point != tilepos.Point) || refindMouse)
                {
                    refindMouse = false;
                    var oldMousePath = mousePath;
                    TilePathFinder path = new TilePathFinder((TileWorld)this.World);
                    mousePoint = tilepos.Point;

                    GuiViewHandler view = this.GuiController.GuiView;
                    Path<TileWorld, TilePosition> foundPath;

                    bool hasPath;
                    var entities = this.World.GetEntities(tilepos).OfType<UnitEntity>();
                    attackUnit = entities.FirstOrDefault(ent => ent.Module<UnitInfoModule>().Controller != this.GuiController.GuiInfo.Player);

                    RemoveColorOfLastFound();
                    if (attackUnit == null)
                    {
                        hasPath = path.FindFirst(lastpos, tilepos, out foundPath);
                        this.lastFoundEnemy = null;
                    }
                    else
                    {

                        Predicate<TilePosition> goalcond = pos =>
                        {
                            //var pointP = pos.Point;
                            //int difx = Math.Abs(pointP.X - mousePoint.X);
                            //int dify = Math.Abs(pointP.Y - mousePoint.Y);
                            //int attackrange = unitEntity.Module<AttackModule>().AttackRange;
                            //return attackrange >= difx && attackrange >= dify;
                            return unitEntity.Module<AttackModule>().CanReachPoint(pos.Point, mousePoint);

                        };
                        hasPath = path.FindFirst(lastpos, goalcond, pos => new Vector(pos.Point, mousePoint).Distance, out foundPath);
                        this.lastFoundEnemy = attackUnit;
                        var gobj= this.GuiController.Factory.GameObjectFromModel(attackUnit);
                        gobj.renderer.material.color = Color.red;

                    }

                    if (hasPath)
                    {
                        int movelength = unitEntity.Module<MoveModule>().MoveLength-this.pathLength();

                        mousePath = new Path<TileWorld,TilePosition>(foundPath.Map,foundPath.Road.Skip(1).Take(movelength));
                    }

                    view.drawRoute(mousePath,this.GuiController.GuiInfo.FocusColor);
                    if (oldMousePath.Map != null)
                        view.unDrawRoute(oldMousePath);

                }
            }

            if (Input.GetButtonDown("select_object") && !enemySelected)
            {

                if(mousePath.Map != null)
                {

                    fullroute.AddLast(mousePath);
                    if(mousePath.Road.Last != null)
                        this.lastpos = mousePath.Road.Last.Value;
                    this.GuiController.GuiView.unDrawRoute(mousePath);
                    mousePath = default(Path<TileWorld, TilePosition>);

                    QueueDeclareAction(this.lastFoundEnemy);
                    this.enemySelected = this.lastFoundEnemy != null;

                    //Finished = true;
                }
            }
            else if (Input.GetButtonDown("deselect_object"))
            {
                enemySelected = false;
                fullroute.RemoveLast();
                if (fullroute.Count == 0)
                    lastpos = this.unitEntity.PositionAs<TilePosition>();
                else
                    lastpos = this.fullroute.Last.Value.Road.Last.Value;
                QueueDeclareAction();
                this.refindMouse = true;
            }
            else if (Input.GetButtonDown("accept") || enemySelected || this.unitEntity.Module<MoveModule>().MoveLength == pathLength())
            {
                this.unit.renderer.material.color = originalColor;
                if(mousePath.Map !=null)
                    this.GuiController.GuiView.unDrawRoute(this.mousePath);
                RemoveColorOfLastFound();
                Finished = true;
            }
        }
コード例 #10
0
        private void QueueDeclareAction(UnitEntity attackUnit = null)
        {
            Path<TileWorld, TilePosition> fullpath;
            if (fullroute.Count == 0)
                fullpath = new Path<TileWorld, TilePosition>(this.WorldAs<TileWorld>());
            else
                fullpath = new Path<TileWorld, TilePosition>(fullroute);

            DeclareMoveAttackCommand declareAction;
            if (attackUnit == null)
                declareAction = new DeclareMoveAttackCommand(this.GuiController.GuiInfo.Player, fullpath);
            else
            {
                declareAction = new DeclareMoveAttackCommand(this.GuiController.GuiInfo.Player, fullpath, attackUnit);

            }
            this.unitEntity.QueueAction(declareAction);
        }
コード例 #11
0
 public void SetEntity(UnitEntity entity)
 {
     this.entity = entity;
 }