Пример #1
0
 public AttackRollResult(UnitGroup unitGroup, int attack, int baseDamage, int bonusDamage, bool isCritical)
 {
     this.UnitGroup = unitGroup;
     this.Attack = attack;
     this.BaseDamage = baseDamage;
     this.BonusDamage = bonusDamage;
     this.IsCritical = isCritical;
 }
Пример #2
0
 public void MoveGroup(Vector3 pos)
 {
     activeEngage      = false;
     targetGroup       = null;
     UnitGroupPosition = pos;
     for (int i = 0; i < unitList.Count; i++)
     {
         unitList[i].MoveUnit(UnitGroupPosition + unitOffset[i]);
     }
 }
Пример #3
0
    private void RemoveUnit(ResUnit removedUnit)
    {
        allUnits.Remove(removedUnit);
        grid.RemoveUnit(removedUnit);
        UnitGroup removedUnitGroup = removedUnit.group;

        removedUnit.group.RemoveUnit(removedUnit);
        removedUnit.tile.RemoveUnit();
        Destroy(removedUnit.gameObject);
    }
Пример #4
0
 public static void SetPursueCommand(List <UnitGroup> pursuers, UnitGroup target)
 {
     foreach (var pursuer in pursuers)
     {
         if (pursuer != null && pursuer != target)
         {
             pursuer.command = new PursueCommand(pursuer, target);
         }
     }
 }
Пример #5
0
 public static void SetAttackCommand(List <UnitGroup> attackingGroups, UnitGroup target)
 {
     foreach (var attackingGroup in attackingGroups)
     {
         if (attackingGroup != null && attackingGroup != target)
         {
             attackingGroup.command = new AttackCommand(attackingGroup, target);
         }
     }
 }
Пример #6
0
 // Public Unit Group Functions
 public void AttackGroup(UnitGroup target)
 {
     activeEngage      = true;
     targetGroup       = target;
     UnitGroupPosition = target.UnitGroupPosition;
     for (int i = 0; i < unitList.Count; i++)
     {
         unitList[i].MoveUnit(target.ClosestUnit(unitList[i].gameObject.transform.position));
     }
 }
Пример #7
0
    //function that is called for a tower that is going to attack, but is waiting on an AI to send units to it
    public IEnumerator StartOverloadAttack(TowerBehavior destination, float percent, float time)
    {
        yield return(new WaitForSeconds(time));

        UnitGroup currentGroup = UnitController.CreateUnitGroupForFaction(myTower.Faction, (int)(myTower.StationedUnits * percent));

        currentGroup.PrepareUnits(myTower);
        myCoroutine = this.WaittoAttack(currentGroup, destination, 1f);
        AIController.CallCoroutine(myCoroutine);
    }
Пример #8
0
    private void MouseActivity()
    {
        if (Input.GetMouseButtonDown(0))
        {
            buildSelectionZone();
        }
        if (Input.GetMouseButtonDown(1))
        {
            RightMouseClick();
        }

        if (Input.GetMouseButton(0))
        {
            if (colliderSelectionZone != null && !colliderSelectionZone.Value.Contains(Input.mousePosition))
            {
                colliderSelectionZone = null;
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (colliderSelectionZone != null)
            {
                colliderSelectionZone = null;
                LeftMouseClick();
            }
            else
            {
                Vector3    center    = Camera.main.ScreenToViewportPoint(selectionZone.Zone.center);
                Collider[] colliders = Physics.OverlapBox(center, new Vector3(selectionZone.Zone.size.x, 1, selectionZone.Zone.y));
                if (colliders.Length == 1)
                {
                    LeftMouseClick();
                }
                else if (colliders.Length > 1)
                {
                    GameObject group = Instantiate(prototype);
                    group.transform.parent = gameObject.transform;
                    UnitGroup uGroup = group.GetComponent <UnitGroup>();
                    Debug.Log(uGroup.Group);
                    foreach (Collider c in colliders)
                    {
                        if (c.gameObject.GetComponent <Unit>() != null)
                        {
                            uGroup.Group.Add(c.gameObject.GetComponent <SteeringBehavior>());
                            Debug.Log(c.gameObject.name);
                        }
                    }
                    player.SelectedObject = uGroup;
                    uGroup.GetComponent <Unit>().SetSelection(true, player.hud.GetPlayingArea());
                }
            }
            selectionZone.enabled = false;
        }
    }
Пример #9
0
    // Replaced MoveUnits
    /// <summary>
    /// Sets a unit group's unit's to move toward a destination tower from an origin tower.
    /// </summary>
    /// <param name="group">Unit group to move.</param>
    /// <param name="origin">Tower were group should move from.</param>
    /// <param name="destination">Tower were group will move toward.</param>
    public static void MoveGroupFromTo(UnitGroup group, TowerBehavior origin, TowerBehavior destination)
    {
        origin.stationedGroup.SubtractUnits(group.UnitCount);
        group.MoveUnits(destination);
        var info = new MovedUnitsInfo(origin, destination, group.UnitCount);

        if (UnitsMoved != null)
        {
            UnitsMoved(info);
        }
    }
Пример #10
0
        /// <summary>Creates display for found group</summary>
        private void CreateGroupDisplay()
        {
            UnitGroup group = UnitGroupHandler.GetGroup(groupCount);

            groupsToDisplay.Add(group);

            UnitGroupInfo info = Instantiate(prefabUnitGroupInfo, transform).GetComponent <UnitGroupInfo>();

            infoComponents.Add(info);
            info.AssignGroupToDisplay(group);
        }
Пример #11
0
        public ActionResult <int> GetFirstUnitGroupIdByUserId(int userId)
        {
            ApartmentsDbContext con       = new ApartmentsDbContext();
            UnitGroup           unitGroup = con.UnitGroups.FirstOrDefault(unitGroup => unitGroup.UserId == userId);

            if (unitGroup == null)
            {
                return(NotFound());
            }
            return(unitGroup.Id);
        }
Пример #12
0
 public void Dismiss()
 {
     if (group != null)
     {
         group.RemoveUnit(this);
         group = null;
         inGroupTargetPosition = Vector3.zero;
         followInGroupTarget   = false;
         SoundManager.instance.removeMusicLayer();
     }
 }
Пример #13
0
    public override int takeAction(UnitGroup enemies, UnitGroup allies)
    {
        Skill toUse  = new Slash();
        Unit  target = toUse.act(allies, enemies, 0);

        if (target != null)
        {
            return(target.takeDamage(mainWeapon.attackPower));
        }
        return(0);
    }
Пример #14
0
 internal void UpdateLayout(UnitGroup unit)
 {
     foreach (var group in mindGroupList)
     {
         if (group.UnitExists(unit))
         {
             group.UpdateLayout();
             return;
         }
     }
 }
Пример #15
0
        public int SolveParallelCompatibilityConflicts()
        {
            foreach (var pl in new List <TaskPlan2>(actorGroupAsUG.GetThisGroupPlans()))
            {
                if (pl.GetCurrentTaskInPlan() != this)
                {
                    UnitGroup ug = pl.GetCurrentTaskInPlan().GetActorGroup() as UnitGroup;
                }
            }

            return(0);
        }
Пример #16
0
    public static void AddUnitsToGroup(UnitGroup group, int numUnits)
    {
        var units = current.groupUnitsMap[group.ID];

        group.AddUnits(numUnits);
        for (int i = 0; i < numUnits; i++)
        {
            var unit = CreateUnitForFaction(group.Faction);
            unit.SetGroup(group);
            units.Add(unit);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!_texture)
        {
            _texture = videoRenderer.getWebCamTexture();
            //            Debug.Log(_texture.width);
        }
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit   hit;
            MeshCollider collie = videoRenderer.gameObject.GetComponentInChildren <MeshCollider>();

            if (!collie.Raycast(Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z)), out hit, 2000f))
            {
                return;
            }

            Renderer     rend         = hit.transform.GetComponent <Renderer>();
            MeshCollider meshCollider = hit.collider as MeshCollider;

            if (rend == null || meshCollider == null)
            {
                return;
            }

            Vector2 pixelUV = hit.textureCoord;
            pixelUV.x *= 1280f;
            pixelUV.y *= 720f;

            Color32 color = (Color32)_texture.GetPixel((int)pixelUV.x, (int)pixelUV.y);
            ctp.colorTargets.Add(new Vexpot.ColorTarget(color, tolerance));
            ctp.StopColorTracker();
            ctp.UpdateColorTargets();
            ctp.StartColorTracker();

            _factory.CreateUnit(color);
            _constructor.ColorSelected(color);
        }

        if (Input.GetMouseButtonDown(0))
        {
            UnitGroup ug = null;
            if (_gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))) != null)
            {
                ug = _gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)));
            }
            if (ug != null)
            {
                _constructor.SetActiveUnit(ug.gameObject, true);
                _logController.updateStats(ug.info);
            }
        }
    }
 private static void AssertCreateFails(UnitGroup group, UnitDto dto)
 {
     try
     {
         Unit.Create(dto, group);
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.IsNotInstanceOfType(e, typeof(AssertFailedException));
     }
 }
Пример #19
0
    public UnitGroup split()
    {
        if (units.Count == 1)
        {
            return(null);
        }
        // k-means clustering
        RandomSet <Unit> unitset = new RandomSet <Unit>(units);

        List <Unit>[] kgroups = new List <Unit> [2];
        Vector2[]     kmeans  = new Vector2[2];
        for (int k = 0; k < 2; ++k)
        {
            kgroups[k] = new List <Unit>();
        }
        for (int repetition = 0; repetition < 10; ++repetition)
        {
            for (int k = 0; k < 2; ++k)
            {
                if (kgroups[k].Count == 0)
                {
                    kmeans[k] = unitset.getRandom().transform.position;
                }
                else
                {
                    kmeans[k] = avgPos(kgroups[k]);
                }
                kgroups[k].Clear();
            }
            foreach (Unit u in units)
            {
                int   closest = 0;
                float mindd   = float.MaxValue;
                for (int k = 0; k < 2; ++k)
                {
                    float dd = (kmeans[k] - (Vector2)u.transform.position).sqrMagnitude;
                    if (dd < mindd)
                    {
                        mindd   = dd;
                        closest = k;
                    }
                }
                kgroups[closest].Add(u);
            }
        }
        // TODO: prefer equally sized groups
        UnitGroup newGroup    = Scene.get().createUnitGroup(kgroups[1]);
        Vector2   groupOffset = (kmeans[1] - kmeans[0]).normalized;

        newGroup.setDest(dest + groupOffset / 2, false);
        setDest(dest - groupOffset / 2, false);
        return(newGroup);
    }
Пример #20
0
    public UnitGroup CreateNewGroup(string tag)
    {
        if (groups == null)
        {
            groups = new List <UnitGroup>();
        }
        var group = new UnitGroup(tag);

        group.index = groups.Count;
        groups.Add(group);
        return(group);
    }
Пример #21
0
    void Start()
    {
        foreach (GameObject rectangle in GameObject.FindGameObjectsWithTag("Rectangles"))
        {
            //if (rectangle.gameObject.name == "FocusRectangle")
            //FocusSprite = rectangle.GetComponent<FocusRectangleObject>();
            if (rectangle.gameObject.name == "SelectionRectangle")
            {
                SelectionSprite = rectangle.GetComponent <SelectorScript>();
            }
            else if (rectangle.gameObject.name == "GroupRectangle")
            {
                GroupSprite = rectangle.GetComponent <GroupRectangleScript>();
            }
        }

        MouseEvents.Setup(gameObject);

        SelectedGroup = ScriptableObject.CreateInstance <UnitGroup>();
        SelectedGroup.startGroup();

        //scrolling = (GetComponent<Scrolling>()) ? GetComponent<Scrolling>() : null;

        //if (camera.name == null)
        //{
        camera = Camera.main;
        //}
        Scale = new Vector2((camera.pixelRect.width / gameObject.guiTexture.texture.width), (camera.pixelRect.height / gameObject.guiTexture.texture.height));


        //gameObject.guiTexture.pixelInset = new Rect(0, -camera.pixelHeight, camera.pixelWidth, camera.pixelHeight);
        //if (gameObject.GetComponent<GUIText>() == null) gameObject.AddComponent<GUIText>();

        gameObject.guiText.pixelOffset = new Vector2(-Camera.main.pixelWidth / 2 + 25 * Scale.x, Camera.main.pixelHeight / 2 - 80 * Scale.y);
        MapViewArea = new Rect(20 * Scale.x, 20 * Scale.y, 1675 * Scale.x, 1047 * Scale.y);
        MainGuiArea = new Rect(1716 * Scale.x, 20 * Scale.y, 184 * Scale.x, 1047 * Scale.y);
        gameObject.guiText.fontSize = (int)(40f * Scale.x + 0.5f);

        //guiTexture.pixelInset = MapViewArea;
        //guiTexture.guiTexture.border.left = (int)(20f * Scale.x);
        //guiTexture.guiTexture.border.right = (int)(225f * Scale.x);
        //guiTexture.guiTexture.border.top = (int)(20f * Scale.y);
        //guiTexture.guiTexture.border.bottom = (int)(13f * Scale.y);


        //QamAcsess = Camera.main.GetComponent<camScript>();

        MouseEvents.LEFTCLICK   += MouseEvents_LEFTCLICK;
        MouseEvents.RIGHTCLICK  += MouseEvents_RIGHTCLICK;
        MouseEvents.LEFTRELEASE += MouseEvents_LEFTRELEASE;

        UpdateManager.GUIUPDATE += UpdateManager_GUIUPDATE;
    }
 public void ThatConstrucionWithEmptyNameThrowsException()
 {
     try
     {
         UnitGroup.Create(new UnitGroupDto());
         Assert.Fail();
     }
     catch (System.Exception e)
     {
         Assert.IsNotInstanceOfType(e, typeof(AssertFailedException));
     }
 }
Пример #23
0
 public UnitGroup(UnitGroup U)
 {
     ID          = U.ID;
     unitsAmount = U.unitsAmount;
     HPperUnit   = U.HPperUnit;
     Weaknesses  = U.Weaknesses;
     Inmunnity   = U.Inmunnity;
     attackPower = U.attackPower;
     initiative  = U.initiative;
     damageType  = U.damageType;
     faction     = U.faction;
 }
        private static Unit CreateUnit()
        {
            var group =
                UnitGroup.Create(new UnitGroupDto
            {
                Name            = UnitTestFixtures.GetTestUnitMilligram().UnitGroupName,
                AllowConversion = UnitTestFixtures.GetTestUnitMilligram().AllowConversion
            });
            var unit = Unit.Create(UnitTestFixtures.GetTestUnitMilligram(), group);

            return(unit);
        }
Пример #25
0
    void OnTriggerExit2D(Collider2D other)
    {
        if (candidateGroup == null)
        {
            return;
        }

        if (other.gameObject.tag == "Army")
        {
            candidateGroup = null;
        }
    }
Пример #26
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (candidateGroup != null)
        {
            return;
        }

        if (other.gameObject.tag == "Army")
        {
            candidateGroup = other.gameObject.GetComponent <UnitGroup> ();
        }
    }
Пример #27
0
 private static void AssertCreateFails(UnitGroup group, UnitDto dto)
 {
     try
     {
         Unit.Create(dto, group);
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.IsNotInstanceOfType(e, typeof (AssertFailedException));
     }
 }
Пример #28
0
        /// <summary>creates formation input info for each stored formation setting</summary>
        private void CreateFormationInput()
        {
            int       startingKey = (int)KeyCode.Alpha1;
            UnitGroup group       = UnitGroupHandler.GetGroup(groupGrab);

            foreach (FormationSetting setting in group.Formation.StoredSettings)
            {
                KeyCode key = (KeyCode)startingKey;
                Instantiate(prefabFormationInput, layoutTransform).GetComponent <FormationInputInfo>().Setup(setting.Name, key);
                startingKey++;
            }
        }
Пример #29
0
    public virtual void OnUnitTick(Unit unit, float dt)
    {
        if (unit.Suspended || unit.IsDoingOr(Unit.kDoingObstinate))
        {
            // 如果正在固执做事或正在施法
            return;
        }

        if (unit.IsDoingOr(Unit.kDoingCasting) && !unit.IsDoingOr(Unit.kDoingMoving))
        {
            // 原地施法
            return;
        }

        UnitNode d = unit.Node;

        ActiveSkill atk = unit.AttackSkill;

        if (atk == null)
        {
            return;
        }

        // 追击目标仍在仇恨区内就继续追击
        if (unit.CastActiveSkill == atk && unit.CastTarget.TargetType == CommandTarget.Type.kUnitTarget)
        {
            Unit tt = unit.CastTarget.TargetUnit;
            if (tt != null)
            {
                UnitNode ttd = tt.Node;
                if (ttd != null && unit.IsDoingAnd(Unit.kDoingCasting | Unit.kDoingMoving) && Vector2.Distance(d.position, ttd.position) < unit.HostilityRange)
                {
                    // 正在追击施法,距离在仇恨范围内
                    return;
                }
            }
        }

        Unit t = UnitGroup.getNearestUnitInRange(unit.World, d.position, unit.HostilityRange, UnitGroup.MatchFunctionLivingEnemy, unit.force);

        if (t == null || t.isDead)
        {
            // 搜不到仇恨区内的目标,有没有必要设置为doNothing?
            return;
        }

        if (unit.CastActiveSkill != atk || unit.CastTarget.TargetUnit != t)
        {
            //Debug.LogFormat("{0} want to attack {1}.", unit.Name, t.Name);
            unit.CommandCastSpell(new CommandTarget(t), atk, false);
        }
    }
Пример #30
0
        public async Task <User> CreateUserAsync(RegisterDTO registerData)
        {
            var buildingTypes = db.BuildingTypes;
            var upgradeTypes  = db.UpgradeTypes;
            var upgrades      = new List <Upgrade>();
            var buildings     = new List <Building>();

            foreach (var buildingType in buildingTypes)
            {
                buildings.Add(new Building
                {
                    Type  = buildingType,
                    Count = 0
                });
            }
            foreach (var upgradeType in upgradeTypes)
            {
                upgrades.Add(new Upgrade
                {
                    Type  = upgradeType,
                    State = UpgradeState.Unresearched
                });
            }
            var buildingGroup = new BuildingGroup
            {
                Buildings = buildings
            };
            var attackingArmy = new UnitGroup();
            var defendingArmy = new UnitGroup();
            var user          = new User
            {
                UserName = registerData.UserName,
                GameId   = 1
            };
            var country = new Country
            {
                Name          = registerData.CountryName,
                BuildingGroup = buildingGroup,
                AttackingArmy = attackingArmy,
                DefendingArmy = defendingArmy,
                Upgrades      = upgrades,
                User          = user,
                Pearl         = 100000,
                Coral         = 100000,
                Stone         = 5000
            };

            user.Country = country;
            await db.SaveChangesAsync();

            return(user);
        }
Пример #31
0
        public void CreateUnitsUnitGroup()
        {
            Unit[] units = new Unit[10];
            for (int i = 0; i < units.Length; i++)
            {
                units[i] = new Unit("Test Unit", i, i.ToString());
            }

            UnitGroup unitGroup = new UnitGroup(units);

            Assert.AreEqual(units.Length, unitGroup.Units.Count);
            Assert.IsTrue(unitGroup.Units.SequenceEqual(units));
        }
Пример #32
0
        public bool getUnitByID(UnitGroup unitGroup, int inputID, Unit expectedOutputUnit)
        {
            Unit startingUnit = new Unit(inputID);

            unitGroup = new UnitGroup(new List <Unit>()
            {
                startingUnit
            });

            Unit returnedUnit = unitGroup.getUnit(inputID);

            return(expectedOutputUnit.ID == returnedUnit.ID);
        }
Пример #33
0
        public static List<Unit> GetUnitListByGroup(UnitGroup group)
        {
            List<Unit> list = new List<Unit>();

            foreach (Unit item in GetUnitList())
            {
                if (item.GetGroup() == group) list.Add(item);
            }

            return list;
        }
Пример #34
0
	private void LoadSaveLua(){
		System.Text.Encoding encodeType = System.Text.Encoding.ASCII;
		string loadedFileSave = "";
		string MapPath = EnvPaths.GetMapsPath();

		loadedFileSave = System.IO.File.ReadAllText(ScenarioData.SaveLua.Replace("/maps/", MapPath), encodeType);

		string loadedFileFunctions = LuaHelper.GetStructureText ("lua_variable_functions.lua");
		//loadedFileFunctions = System.IO.File.ReadAllText(StructurePath + "lua_variable_functions.lua", encodeType);

		string loadedFileEndFunctions = LuaHelper.GetStructureText ("lua_variable_end_functions.lua");
		//loadedFileEndFunctions = System.IO.File.ReadAllText(StructurePath + "lua_variable_end_functions.lua", encodeType);
		
		loadedFileSave = loadedFileFunctions + loadedFileSave + loadedFileEndFunctions;
		
		save = new Lua();
		save.LoadCLRPackage();
		
		try {
			save.DoString(loadedFileSave);
		} catch(NLua.Exceptions.LuaException e) {
			Debug.LogError(ParsingStructureData.FormatException(e), gameObject);
			
			HelperGui.MapLoaded = false;
			return;
		}
		// LoadArea
		ScenarioData.Area = new Rect();
		if(save.GetTable("Scenario.Areas.AREA_1") != null && save.GetTable("Scenario.Areas.AREA_1").ToString() != "null"){
			ScenarioData.DefaultArea = true;
			ScenarioData.Area.x = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[1].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
			ScenarioData.Area.y = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[2].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
			ScenarioData.Area.width = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[3].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
			ScenarioData.Area.height = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[4].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
			UpdateArea();
		}
		else{
			ScenarioData.DefaultArea = false;
			HeightmapControler.TerrainMaterial.SetInt("_Area", ScenarioData.DefaultArea?1:0);
			MapElements.SetActive(false);
			HeightmapControler.TerrainMaterial.SetFloat("_AreaX", 0);
			HeightmapControler.TerrainMaterial.SetFloat("_AreaY", 0);
			HeightmapControler.TerrainMaterial.SetFloat("_AreaWidht", ScenarioData.Size.x / 10f);
			HeightmapControler.TerrainMaterial.SetFloat("_AreaHeight", ScenarioData.Size.y / 10f);
		}

		MapCenterPoint = Vector3.zero;
		MapCenterPoint.x = (ScenarioData.Size.x / 20);
		MapCenterPoint.z = -1 * (ScenarioData.Size.y / 20);
		
		// LoadMarkers
		#region Load Markers
		//int MarkersCount = save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers").Values.Count;

		Mexes = new List<Mex>();
		Hydros = new List<Hydro>();
		ARMY_ = new List<Army>();
		SiMarkers = new List<Marker>();


		//LuaTable MasterChain = save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers") as LuaTable;
		//string[] KeysArray = new string[MarkersCount];
		//MasterChain.Keys.CopyTo(KeysArray, 0);

		LuaHelper.LHTable MarkersTable = new LuaHelper.LHTable(save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers"));

		for(int m = 0; m < MarkersTable.Count; m++){
			//LuaTable MarkerTab = MasterChain[KeysArray[m]] as LuaTable;
			LuaHelper.LHTable MarkerTable = new LuaHelper.LHTable(MarkersTable, MarkersTable.Keys[m]);

			Vector3 MarkerPosParsed = Vector3.zero;
			MarkerTable.GetVector3Value("position", out MarkerPosParsed);

			Vector3 MarkerRotParsed = Vector3.zero;
			MarkerTable.GetVector3Value("orientation", out MarkerRotParsed);

			string TypeOfMarker = MarkerTable.GetStringValue("type");

			if(TypeOfMarker == "Mass"){
				Mex newMex = new Mex();
				newMex.name = MarkersTable.Keys[m];
				
				newMex.position = HeightmapControler.MapPosInWorld(MarkerPosParsed);
				newMex.orientation = MarkerRotParsed;
				
				LuaHelper.ReadSpawnWithArmy(out newMex.SpawnWithArmy, MarkerTable);

				Mexes.Add(newMex);
			}
			else if(TypeOfMarker == "Hydrocarbon"){
				Hydro NewHydro = new Hydro();
				NewHydro.name = MarkersTable.Keys[m];

				NewHydro.size = MarkerTable.GetFloatValue("size");
				NewHydro.amount = MarkerTable.GetFloatValue("amount");
				NewHydro.resource = MarkerTable.GetBoolValue("resource");
				NewHydro.prop = MarkerTable.GetStringValue("prop");

				NewHydro.color = MarkerTable.GetColorValue("color");

				NewHydro.position = HeightmapControler.MapPosInWorld(MarkerPosParsed);
				NewHydro.orientation = MarkerRotParsed;

				LuaHelper.ReadSpawnWithArmy(out NewHydro.SpawnWithArmy, MarkerTable);

				Hydros.Add(NewHydro);
			}
			else if(MarkersTable.Keys[m].Contains("ARMY_")){
				Army NewArmy = new Army();
				NewArmy.name = MarkersTable.Keys[m];

				NewArmy.Id = int.Parse(MarkersTable.Keys[m].Replace("ARMY_", ""));

				NewArmy.position = HeightmapControler.MapPosInWorld(MarkerPosParsed);
				NewArmy.orientation = MarkerRotParsed;

				ARMY_.Add(NewArmy);
			}
			else{
				Marker NewMarker = new Marker();
				NewMarker.name = MarkersTable.Keys[m];
				NewMarker.position = HeightmapControler.MapPosInWorld(MarkerPosParsed);
				NewMarker.orientation = MarkerRotParsed;

				NewMarker.type = TypeOfMarker;
				NewMarker.prop = MarkerTable.GetStringValue("prop");

				// HINT
				NewMarker.hintValue = MarkerTable.GetStringValue("hint");
				NewMarker.hint = MarkerTable.GetBoolValue("hint");

				// GRAPH
				NewMarker.graph = MarkerTable.GetStringValue("graph");

				// adjacentTo
				NewMarker.adjacentTo = MarkerTable.GetStringValue("adjacentTo");


				// Color
				if (!string.IsNullOrEmpty(MarkerTable.GetStringValue("color"))) {
					//Color MyColor = Color.white;
					//ColorUtility.TryParseHtmlString (MarkerTable.GetStringValue("color"), out MyColor);
					NewMarker.Kolor = MarkerTable.GetColorValue("color");

				} else
					NewMarker.Kolor = Color.white;
				

				LuaHelper.ReadSpawnWithArmy(out NewMarker.SpawnWithArmy, MarkerTable);

				SiMarkers.Add(NewMarker);
			}
		}

		SortArmys();

		MexTotalCount = Mexes.Count;
		HydrosTotalCount = Hydros.Count;
		SiTotalCount = SiMarkers.Count;
		#endregion

		#region Load Army Save
		SaveArmys = new List<SaveArmy> ();
		LuaHelper.LHTable ArmiesTable = new LuaHelper.LHTable(save.GetTable("Scenario.Armies"));

		for(int m = 0; m < ArmiesTable.Count; m++){
			LuaHelper.LHTable ArmyTable = new LuaHelper.LHTable(ArmiesTable, ArmiesTable.Keys[m]);
			SaveArmy NewArmy = new SaveArmy();
			NewArmy.Name = ArmiesTable.Keys[m];

			AddSaveArmyMarker(NewArmy.Name);

			NewArmy.personality = ArmyTable.GetStringValue("personality");
			NewArmy.plans = ArmyTable.GetStringValue("plans");
			NewArmy.color = ArmyTable.GetIntValue("color");
			NewArmy.faction = ArmyTable.GetIntValue("faction");

			LuaHelper.LHTable EconomyTable = new LuaHelper.LHTable(ArmyTable, "Economy");
			NewArmy.EconomyMass = EconomyTable.GetIntValue("mass");
			NewArmy.EconomyEnergy = EconomyTable.GetIntValue("energy");

			NewArmy.Alliances = ArmyTable.GetStringArrayValue("Alliances");


			// Get units

			NewArmy.UnitsOrders = "";
			NewArmy.UnitsPlatoon = "";
			NewArmy.Units = new List<UnitGroup>();
			LuaHelper.LHTable ArmyUnitsTable;
			ArmyTable.GetLuaArmyGroup("Units", out NewArmy.UnitsOrders, out NewArmy.UnitsPlatoon, out ArmyUnitsTable);

		
			for(int i = 0; i < ArmyUnitsTable.Count; i++){
				UnitGroup NewUnitGroup = new UnitGroup();
				NewUnitGroup.Name = ArmyUnitsTable.Keys[i];

				LuaHelper.LHTable UnitsGroupTable;
				ArmyUnitsTable.GetLuaArmyGroup(ArmyUnitsTable.Keys[i], out NewUnitGroup.orders, out NewUnitGroup.platoon, out UnitsGroupTable);

				for(int u = 0; u < UnitsGroupTable.Count; u++){
					Unit NewUnit = new Unit();
					LuaHelper.LHTable UnitTable = new LuaHelper.LHTable(UnitsGroupTable, UnitsGroupTable.Keys[u]);

					NewUnit.Name = UnitsGroupTable.Keys[u];
					NewUnit.type = UnitTable.GetStringValue("type");
					NewUnit.orders = UnitTable.GetStringValue("orders");
					NewUnit.platoon = UnitTable.GetStringValue("platoon");
					UnitTable.GetVector3Value("Position", out NewUnit.Position);
					UnitTable.GetVector3Value("Orientation", out NewUnit.Orientation);

					NewUnitGroup.Units.Add(NewUnit);
				}

				NewArmy.Units.Add(NewUnitGroup);
			}
				
			SaveArmys.Add(NewArmy);
		}

		#endregion
	}
Пример #35
0
	void Start () 
    {
        group = ScriptableObject.CreateInstance<UnitGroup>();
        group.ResetGroup();
        gameObject.collider.enabled = false;
    }
Пример #36
0
 public void RemoveEmptyGroup(UnitGroup group)
 {
     if (group.GetTotalQty() == 0)
     {
         if (attackers.Contains(group))
         {
             attackers.Remove(group);
         }
         if (defenders.Contains(group))
         {
             defenders.Remove(group);
         }
     }
 }
Пример #37
0
    // TODO: handle the situation when one side is eliminated completely (end the combat)
    public bool ResolveAttack(UnitGroup targetGroup, int index, AttackRollResult attack)
    {
        Unit target;
        if (index > 0)
        {
            target = targetGroup.GetUnit(index);

            if (target == null)
            {
                Debug.Log("Invalid attack resolution target!");
                return false;
            }

            if (target.Quantity <= 0)
            {
                Debug.Log("Zero Quantity!");
                return false;
            }
        }
        else
        {
            target = targetGroup.GetRandomUnit();
        }

        if (attackers.Contains(targetGroup) && attackers.Contains(attack.UnitGroup))
        {
            Debug.Log("Invalid attack resolution target!");
            return false;
        }

        if (defenders.Contains(targetGroup) && defenders.Contains(attack.UnitGroup))
        {
            Debug.Log("Invalid attack resolution target!");
            return false;
        }

        int defenseRoll = Dice.RollDie(10) + Dice.RollDie(10) + target.UnitType.Defense;
        if ((useCriticals && attack.IsCritical) || (attack.Attack > defenseRoll))
        {
            Debug.Log(attack.Attack.ToString() + " attack vs " + defenseRoll + " defense: hit!");
            int damage = attack.FullDamage;
            if (!attack.UnitGroup.UnitType.Attack.IsAP)
            {
                damage -= target.UnitType.Armor;
            }
            Debug.Log(attack.FullDamage.ToString() + " damage vs " + target.UnitType.Armor + " armor, result = " + damage);

            if (damage > 0)
            {
                target.Quantity -= 1;

                int newHP = target.CurrentHealth - damage;
                Debug.Log("HP: " + target.CurrentHealth + " - " + damage + " = " + newHP);

                if (newHP > 0)
                {
                    Unit reinforced = targetGroup.GetUnitWithHealth(newHP);
                    if (reinforced == null)
                    {
                        Debug.Log("Attempted to reinforce a null unit");
                        return false;
                    }
                    reinforced.Quantity += 1;
                }
            }
        }
        else
        {
            Debug.Log(attack.Attack.ToString() + " attack vs " + defenseRoll + " defense: miss.");
        }

        if (attackerRollResults.Contains(attack))
        {
            attackerRollResults.Remove(attack);
        }
        else
        {
            defenderRollResults.Remove(attack);
        }
        /*
        if (attackerRollResults.Count == 0 && defenderRollResults.Count == 0)
        {
            if (CurrentPhase == attackPhase.CHARGE)
            {
                CurrentPhase = attackPhase.MELEE;
            }
            else
            {
                CurrentPhase = attackPhase.CHARGE;
            }
        }
        */
        return true;
    }
Пример #38
0
 private AttackRollResult GenerateAttackRollResult(UnitGroup attacker)
 {
     bool isCritical = false;
     int dieRoll = Dice.RollDie(10) + Dice.RollDie(10);
     int bonusDamage = 0;
     if (useCriticals && dieRoll >= 18)
     {
         isCritical = true;
         bonusDamage = attacker.UnitType.Attack.RollDamage();
     }
     AttackRollResult result = new AttackRollResult(attacker, dieRoll + attacker.UnitType.Attack.Skill, attacker.UnitType.Attack.RollDamage(), bonusDamage, isCritical);
     return result;
 }
Пример #39
0
        /// <summary>
        /// Register the base value always as 1 using the group, and names.
        /// </summary>
        /// <param name="group">e.g. the group of the units. e.g. length, volume, weight</param>
        /// <param name="abbreviation">abbreviation for the unit e.g "ft" for feet.</param>
        /// <param name="unitsName">The name of the units e.g if group = lenght, unitsName = feet</param>
        /// <param name="alias">Alias for the subgroup</param>
        public void RegisterGroup(string group, string abbreviation, string unitsName, string alias)
        {
            _groups[group] = new UnitGroup() { Name = group, BaseName = unitsName, BaseName2 = alias };
            _subGroupsToGroupMap[unitsName] = group;
            RegisterUnit(group, abbreviation, unitsName, 1);

            if (!string.IsNullOrEmpty(alias))
                RegisterUnit(group, abbreviation, alias, 1);
        }
Пример #40
0
    void Start()
    {
        foreach (GameObject rectangle in GameObject.FindGameObjectsWithTag("Rectangles"))
        {
            //if (rectangle.gameObject.name == "FocusRectangle")
                //FocusSprite = rectangle.GetComponent<FocusRectangleObject>();
            if (rectangle.gameObject.name == "SelectionRectangle")
                SelectionSprite = rectangle.GetComponent<SelectorScript>();
            else if (rectangle.gameObject.name == "GroupRectangle")
                GroupSprite = rectangle.GetComponent<GroupRectangleScript>();
        }
        
        MouseEvents.Setup(gameObject);

        SelectedGroup = ScriptableObject.CreateInstance<UnitGroup>();
        SelectedGroup.startGroup();

        //scrolling = (GetComponent<Scrolling>()) ? GetComponent<Scrolling>() : null;
        
        //if (camera.name == null)
        //{
        camera = Camera.main;
        //}
        Scale = new Vector2((camera.pixelRect.width / gameObject.guiTexture.texture.width), (camera.pixelRect.height / gameObject.guiTexture.texture.height));


        //gameObject.guiTexture.pixelInset = new Rect(0, -camera.pixelHeight, camera.pixelWidth, camera.pixelHeight);
        //if (gameObject.GetComponent<GUIText>() == null) gameObject.AddComponent<GUIText>();

        gameObject.guiText.pixelOffset = new Vector2(-Camera.main.pixelWidth / 2 + 25 * Scale.x, Camera.main.pixelHeight/2 - 80 * Scale.y);
        MapViewArea = new Rect(20 * Scale.x, 20 * Scale.y, 1675 * Scale.x, 1047 * Scale.y);
        MainGuiArea = new Rect(1716 * Scale.x, 20 * Scale.y, 184 * Scale.x, 1047 * Scale.y);
        gameObject.guiText.fontSize = (int)(40f * Scale.x + 0.5f);

        //guiTexture.pixelInset = MapViewArea;
        //guiTexture.guiTexture.border.left = (int)(20f * Scale.x);
        //guiTexture.guiTexture.border.right = (int)(225f * Scale.x);
        //guiTexture.guiTexture.border.top = (int)(20f * Scale.y);
        //guiTexture.guiTexture.border.bottom = (int)(13f * Scale.y);


        //QamAcsess = Camera.main.GetComponent<camScript>();

        MouseEvents.LEFTCLICK += MouseEvents_LEFTCLICK;
        MouseEvents.RIGHTCLICK += MouseEvents_RIGHTCLICK;
        MouseEvents.LEFTRELEASE += MouseEvents_LEFTRELEASE;

        UpdateManager.GUIUPDATE += UpdateManager_GUIUPDATE;

        
    }
Пример #41
0
    // Selection finished -> Now Select the Units inside the Area
    private void SnapSelectionRectangle()
    {
        // Get group of selected elements
        SelectedGroup = SelectionSprite.GetComponent<SelectorScript>().SnapSelection();

        // if group has 1 unit -> do single focus
        if (SelectedGroup.Count == 1)
        {
            GameObject unit = SelectedGroup[0];
            SelectedGroup.ResetGroup();
            unit.AddComponent<Focus>();
            //unit.GetComponent<UnitScript>().ShowLifebar();
        }
        else
        {
            // Activate Lifebar at all selected units
            for (int i = 0; i < SelectedGroup.Count; i++)
                SelectedGroup[i].GetComponent<UnitScript>().ShowLifebar();
        }

        // Hide selection rectangle
        SelectionRectangle = new Rect(SelectionRectangle.x, SelectionRectangle.y, 0f, 0f);
    }
Пример #42
0
		public CaTypeUnitGroup() {
			m_ug = null;
		}
Пример #43
0
		public override string FromSaveString(string strArgs, bool fLast) {
			Regex re = new Regex(@"^(?<index>(-)?\d+)(?<end>.*)$");
			Match m = re.Match(strArgs);
			int index = int.Parse(m.Groups["index"].Value);
			LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
			if (index >= 0 && index < lvld.UnitGroupManager.Items.Count) {
				m_ug = (UnitGroup)lvld.UnitGroupManager.Items[index];
				m_fInit = true;
			}
			return m.Groups["end"].Value;
		}
Пример #44
0
		public override bool EditProperties() {
			StringCollection strc = GetUnitGroupNames();
			string strName = m_ug != null ? m_ug.Name : "";
			int n = PickListForm.DoModal("Unit Group", strName, strc);
			if (n == -1)
				return false;
			LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));			
			m_ug = (UnitGroup)lvld.UnitGroupManager.Items[n];
			m_fInit = true;
			return true;
		}