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;
 }
Exemplo n.º 2
0
        public void FindFirst_5x5EmptyMap_FindsPath()
        {
            TilePathFinder pathfinder = new TilePathFinder((TileWorld)this.World);

            var start = new TilePosition(new Point(0, 0));
            var goal = new TilePosition(new Point(0, -2));
            Path<TileWorld, TilePosition> foundPath;
            var hasPath = pathfinder.FindFirst(start, goal, out foundPath);

            Assert.IsTrue(hasPath);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
 public Transform CreateTile(TerrainEntity terEnt, TilePosition posinfo)
 {
     var pos = posinfo.Point;
     var tileobj = (Transform)Instantiate(TerrainTemplate, new Vector3(-(float)pos.X, (float)pos.Y), TerrainTemplate.rotation);
     gameobjLookUp.Add(terEnt, tileobj.gameObject);
     return tileobj;
 }
Exemplo n.º 5
0
 public TileSpawnInformation(TilePosition pos)
     : base(pos)
 {
 }
        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;
            }
        }
Exemplo n.º 7
0
        private bool AddEntity(XmasEntity xmasEntity, TilePosition pos)
        {
            Point point = pos.Point;

            Tile tile = map[point.X, point.Y];

            if (!tile.CanContain(xmasEntity))
                return false;

            entlocs[xmasEntity] = point;
            tile.AddEntity(xmasEntity);
            return true;
        }
Exemplo n.º 8
0
        private bool SetEntityPosition(XmasEntity xmasEntity, TilePosition pos)
        {
            Point oldPoint;
            bool entityExistsInMap = entlocs.TryGetValue(xmasEntity, out oldPoint);

            if (!AddEntity (xmasEntity, pos))
                return false;

            if (entityExistsInMap)
                map [oldPoint].RemoveEntity (xmasEntity);

            return true;
        }