void LoadData() { string filePath = Application.dataPath + dataProjectFilePath + targetFile + (".json"); if (File.Exists(filePath)) { string jsonAsData = File.ReadAllText(filePath); switch (windowState) { case 0: mechData = JsonUtility.FromJson <MechData>(jsonAsData); break; case 1: componentLoadout = JsonUtility.FromJson <ComponentLoadout>(jsonAsData); break; case 2: mechArray = JsonUtility.FromJson <MechArray>(jsonAsData); break; } } else { mechData = new MechData(); } }
public void LoadMech(string partsTargetFile) { filePath = Application.dataPath + dataProjectFilePath + partsTargetFile + (".json"); jsonAsData = File.ReadAllText(filePath); mechData = JsonUtility.FromJson <MechData>(jsonAsData); if (mechData != null) { if (parts != null) { foreach (GameObject part in parts) { Destroy(part); } parts.Clear(); } foreach (Vector3 entry in mechData.ComponentPositions) { int currentArrayPosition = System.Array.IndexOf(mechData.ComponentPositions, entry); if (mechData.ComponentPrefabs[currentArrayPosition] != null) { print(currentArrayPosition); print(mechData.ComponentPrefabs[currentArrayPosition]); GameObject currentPart = Instantiate(mechData.ComponentPrefabs[currentArrayPosition], mechData.ComponentPositions[currentArrayPosition], Quaternion.identity); parts.Add(currentPart); } } } }
public override bool Draw(List <DrawData> playerDrawData, int drawType, Player drawPlayer, ref Texture2D texture, ref Texture2D glowTexture, ref Vector2 drawPosition, ref Rectangle frame, ref Color drawColor, ref Color glowColor, ref float rotation, ref SpriteEffects spriteEffects, ref Vector2 drawOrigin, ref float drawScale, float shadow) { //drawPlayer.direction = 1; //Main.NewText("drawpos =" + drawPosition); if (drawType == 2) { MechData dat = (MechData)drawPlayer.mount._mountSpecificData; Vector2 dir = -Main.screenPosition + drawPlayer.position + new Vector2(0, -156); Vector2 initPos = dir + new Vector2(60, 22); Texture2D gunTex = mod.GetTexture("Mounts/MechGatlingGun"); Texture2D laserTex = mod.GetTexture("Mounts/MechLaserGun"); int laserFrameOffset = 0; Texture2D mountTex = mod.GetTexture("Mounts/Mech_Back"); Texture2D frontTex = mod.GetTexture("Mounts/Mech_Front"); if (dat.stasis) { gunTex = mod.GetTexture("Mounts/MechGatlingGun_Alt"); } if (dat.stasis) { laserFrameOffset = laserTex.Height / 2; } playerDrawData.Insert(0, new DrawData(mountTex, dir - new Vector2(170, 200), new Rectangle(0, drawPlayer.mount._frame * (mountTex.Height / mountData.totalFrames), mountTex.Width, mountTex.Height / mountData.totalFrames), Color.White, 0f, new Vector2(0, 0), 1f, SpriteEffects.None, 0)); playerDrawData.Add(new DrawData(frontTex, dir - new Vector2(170, 200), new Rectangle(0, drawPlayer.mount._frame * (mountTex.Height / mountData.totalFrames), mountTex.Width, mountTex.Height / mountData.totalFrames), Color.White, 0f, new Vector2(0, 0), 1f, SpriteEffects.None, 0)); playerDrawData.Add(new DrawData(laserTex, initPos - new Vector2(62, 48 + 128 - dat.gunOffset), new Rectangle(0, laserFrameOffset, laserTex.Width, laserTex.Height / 2), Color.White, dat.laserRotation, new Vector2(34, laserTex.Height / 4), 1f, SpriteEffects.None, 0)); //Main.spriteBatch.DrawString(Main.fontDeathText, "Charge = " + Math.Truncate(dat.charge) + "%", new Vector2((Main.screenWidth - Main.fontDeathText.MeasureString("Charge = " + Math.Truncate(dat.charge) + "%").X) / 2, 50), Color.Blue); playerDrawData.Add(new DrawData(gunTex, initPos - new Vector2(60, 48 - dat.gunOffset), new Rectangle(0, dat.GetFrame() * (gunTex.Height / 4), gunTex.Width, gunTex.Height / 4), Color.White, dat.gunRotation, new Vector2(10 + (gunTex.Height / 8), gunTex.Height / 8), 1f, SpriteEffects.None, 0)); } return(false); }
public void AddPickupEffect(Player player) { if (player.mount.Type == ModContent.MountType <Mech>()) { MechData md = (MechData)player.mount._mountSpecificData; md.SetNewEffect(effect, duration); } }
// Use this for initialization void Start() { //Mech mech = new Mech(); //mech.mechType = "HER-2S Hermes II"; //mech.movementPoint.walk = 6; //mech.movementPoint.run = 9; //mech.tonnage = 40; //mech.mechWarrior.name = "John Doe"; //mech.mechWarrior.gunnery = 5; //mech.mechWarrior.piloting = 4; //mech.armorValues = new ArmorValues[8]; //mech.armorValues[0].location = MechLocation.Head.ToString(); //mech.armorValues[0].armor = 9; //mech.armorValues[1].location = MechLocation.LeftTorso.ToString(); //mech.armorValues[1].armor = 14; //mech.armorValues[2].location = MechLocation.RightTorso.ToString(); //mech.armorValues[2].armor = 14; //mech.armorValues[3].location = MechLocation.CenterTorso.ToString(); //mech.armorValues[3].armor = 17; //mech.armorValues[4].location = MechLocation.LeftArm.ToString(); //mech.armorValues[4].armor = 11; //mech.armorValues[5].location = MechLocation.RightArm.ToString(); //mech.armorValues[5].armor = 11; //mech.armorValues[6].location = MechLocation.LeftLeg.ToString(); //mech.armorValues[6].armor = 14; //mech.armorValues[7].location = MechLocation.RightLeg.ToString(); //mech.armorValues[7].armor = 14; //MechData mechdata = new MechData(); //mechdata.mechs = new List<Mech>(); //mechdata.mechs.Add(mech); //mechdata.mechs.Add(mech); //File.WriteAllText(Application.dataPath + "/MechData.txt", JsonUtility.ToJson(mechdata, true)); //Weapon weapon = new Weapon(); //weapon.type = "Autocannon 5"; //weapon.damage = 5; //weapon.range.close = 6; //weapon.range.medium = 12; //weapon.range.far = 18; //weapon.categoryValue = Category.Projectile.ToString(); //WeaponData weapondata = new WeaponData(); //weapondata.weapons = new List<Weapon>(); //weapondata.weapons.Add(weapon); //weapondata.weapons.Add(weapon); //File.WriteAllText(Application.dataPath + "/WeaponData.txt", JsonUtility.ToJson(weapondata, true)); string mechJson = File.ReadAllText(Application.dataPath + "/MechData.txt"); MechData mechs = JsonUtility.FromJson <MechData>(mechJson); string weaponJson = File.ReadAllText(Application.dataPath + "/WeaponData.txt"); WeaponData weapons = JsonUtility.FromJson <WeaponData>(weaponJson); Debug.Log("Mechs loaded: " + mechs.mechs.Count); Debug.Log("Weapons loaded: " + weapons.weapons.Count); }
//public MeshRenderer meshRenderer; public void DrawMesh(MechData m, MeshCollider meshCollider) { Mesh mesh = m.CreateMesh(); meshFilter.sharedMesh = mesh; meshFilter.transform.localScale = Vector3.one * FindObjectOfType <display>().meshSettings.uniformScale; //meshCollider.sharedMesh = mesh; }
/// <summary> /// Загрузить данные о чекпоинте /// </summary> public void SetData(InterObjData _intObjData) { MechData chData = (MechData)_intObjData; if (chData != null) { activated = chData.activated; } }
private void LoadData() { string mechJson = File.ReadAllText(Application.dataPath + "/Data/MechData.txt"); mechData = JsonUtility.FromJson <MechData>(mechJson); string weaponJson = File.ReadAllText(Application.dataPath + "/Data/WeaponData.txt"); weaponData = JsonUtility.FromJson <WeaponData>(weaponJson); }
/// <summary> /// Загрузить данные о механизме /// </summary> public void SetData(InterObjData _intObjData) { MechData mData = (MechData)_intObjData; if (mData != null) { activated = mData.activated; StopAllCoroutines(); StartCoroutine(AppearProcess()); } }
public void Init(Battle newBattle, MechData mechData) { this.battle = newBattle; this.data = mechData; this.hp = this.data.maxHP; this.maxActionPoints = 5f; // temporary constant this.actionPoints = this.maxActionPoints; this.fireAuto = true; this.isDestroyed = false; }
public override bool UpdateFrame(Player mountedPlayer, int state, Vector2 velocity) { MechData dat = (MechData)mountedPlayer.mount._mountSpecificData; dat.gunOffset = 0; dat.UpdateEffect(); if (velocity.Y != 0) { dat.gunOffset = -16; } if (((MechData)mountedPlayer.mount._mountSpecificData).stasis == true) { mountedPlayer.velocity.X = 0f; mountedPlayer.velocity.Y = Math.Max(mountedPlayer.velocity.Y, 0); mountedPlayer.mount._frame = 10; return(false); } int runningFrameDelay = mountData.runningFrameDelay; if (mountedPlayer.GetModPlayer <PlayerFixer>().mechRunSpeed) { runningFrameDelay = 15; } if (mountedPlayer.mount._frame <= 1) { return(true); } else { if (velocity.Y != 0 || velocity == Vector2.Zero) { return(true); } mountedPlayer.mount._frameCounter += 2.4f; if (mountedPlayer.mount._frameCounter >= runningFrameDelay) { mountedPlayer.mount._frameCounter = 0; mountedPlayer.mount._frame += Math.Sign(velocity.X); } if (mountedPlayer.mount._frame < 2) { mountedPlayer.mount._frame = 9; } if (mountedPlayer.mount._frame > 9) { mountedPlayer.mount._frame = 2; } //mountedPlayer.mount._frame = 2; } return(false); }
public override bool CanPickup(Player player) { if (player.mount.Type == ModContent.MountType <Mech>()) { MechData md = (MechData)player.mount._mountSpecificData; return(md.CanPickupUpgrade()); } else { return(false); } }
private static void DrawPowerupSelect(MechData dat, int ypos) { Mod mod = ModContent.GetInstance <StarSailorMod>(); int w = mod.GetTexture("Items/FirePowerup").Width; Texture2D selectionTexture = mod.GetTexture("Items/PowerupHighlight"); int leftPos = (Main.screenWidth / 2) - (int)(w * 4.5f); ypos -= 85; foreach (CannonEffects cef in typeof(CannonEffects).GetEnumValues()) { Texture2D texlay = MechData.GetEffectIconTexture(cef); int index = (int)cef; int xC = index <= 4 ? index : index + 1; //yeah //int xC = index; int timer = dat.currEffects[cef]; int dispSecs = timer / 60; Color color; if (!Main.LocalPlayer.GetModPlayer <PlayerFixer>().UnlockedMechEffect(cef)) { color = Color.Black; } else if (cef == CannonEffects.Base) { color = Color.White; } else if (timer >= 0) { if (MechData.GetChargeCost(cef) <= dat.charge) { color = Color.White; } else { color = Color.LightCyan; } } else { color = Color.Gray; } Main.spriteBatch.Draw(texlay, new Rectangle(leftPos + (xC * w), ypos, w, w), color); if (cef != CannonEffects.Base && timer >= 0) { Main.spriteBatch.DrawString(Main.fontItemStack, dispSecs + "s", new Vector2(leftPos + (xC * w), ypos + w), Color.White); } if (cef == dat.selectedEffect) { Main.spriteBatch.Draw(selectionTexture, new Rectangle(leftPos + (xC * w), ypos, w, w), Color.White); } } }
/// <summary> /// Загрузить данные о механизме /// </summary> public virtual void SetData(InterObjData _intObjData) { MechData mData = (MechData)_intObjData; if (mData != null) { activated = mData.activated; if (anim != null) { anim.Play(activated ? "Active" : "Inactive"); } } }
private Vector2 LaserOrigin(Player player) { if (player.mount.Type == ModContent.MountType <Mech>()) { MechData dat = (MechData)player.mount._mountSpecificData; Vector2 dirac = new Vector2(1, 0).RotatedBy(dat.laserRotation); return(player.position + new Vector2(0, -293) + (20 * dirac)); } else { return(player.Center + new Vector2(-10, -345)); //this hopefully shouldn't get called but just in case } }
public static MechData GetMech(string name) { foreach (MechData m in GameData.instance.mechs) { if (m.name == name) { return(m); } } MechData invalid = new MechData(); invalid.name = "Invalid"; return(invalid); }
public override void UpdateEffects(Player player) { MechData dat = (MechData)player.mount._mountSpecificData; player.ChangeDir(1); if (dat.stasis) { dat.gunRotation = (float)Math.PI / 2f; } base.UpdateEffects(player); }
private Mech loadMechData(MechData mechdata) { Type mechClass = UniTable.GetTypeFromGuid(new Guid(mechdata.mechTypeId)); if (mechClass == null) { Debug.Log("no such class found"); return(null); } //load mech Mech newMech = (Mech)pManager.pDataManager.transform.gameObject.AddComponent(mechClass); newMech.Initialize(); newMech.unitId = new Guid(mechdata.mechUnitId); //load abilities foreach (String g in mechdata.abilityIds) { Guid mechGuid = new Guid(g); ability a = UniTable.abilityDictionary[UniTable.classGuid[UniTable.GetTypeFromGuid(mechGuid)]].clone(); a.parent = newMech; newMech.abilities.Add(a); } Debug.Log(newMech.abilities.Count); //load dynamic attributes newMech.dynamicAttributes.setTo(mechdata.dynamicAtt); //load base attributes newMech.baseAtt.setTo(mechdata.baseAtt); //load mech class info foreach (partOwnership ownedPart in mechdata.parts) { Debug.Log("slot: " + ownedPart.slot + " has item: " + ownedPart.partId); Guid partGuid = new Guid(ownedPart.partId); newMech.addPartAs(masterInventory.getPart(partGuid, ownedPart.slot), ownedPart.slot); } //load unit class info newMech.MovementSpeed = mechdata.movementSpeed; newMech.PlayerNumber = mechdata.playerNumber; newMech.displayName = mechdata.displayName; return(newMech); }
public void Initialize(MechData mechData, Helper helper) { base.Initialize(helper); MechData = mechData; SetName(MechData.Name); Health.Setup(MechData.MaxHealth); Pushable = AddUnitComponent <UnitPushableComponent>(); PrimaryWeapon = AddUnitComponent <UnitWeaponComponent>(); PrimaryWeapon.WeaponData = MechData.DefaultPrimaryWeapon; SecondaryWeapon = AddUnitComponent <UnitWeaponComponent>(); SecondaryWeapon.WeaponData = MechData.DefaultSecondaryWeapon; Assert.IsNotNull(MechData.View, "Missing view."); Instantiate(MechData.View).transform.SetParent(transform, false); }
// Determine first and second team as per initiative roll. first team lost initiative roll. second team won. private void DetermineInitiative(out MechData firstTeam, out MechData secondTeam) { int iniA = BattleTechTables.Instance.Roll(2); int iniB = BattleTechTables.Instance.Roll(2); while (iniA == iniB) { iniA = BattleTechTables.Instance.Roll(2); iniB = BattleTechTables.Instance.Roll(2); } if (iniA > iniB) { firstTeam = teams[1]; secondTeam = teams[0]; } else { firstTeam = teams[0]; secondTeam = teams[1]; } }
public static void DrawChargeMeter(MechData dat) { Mod mod = ModContent.GetInstance <StarSailorMod>(); int numSegs = 10; float nb = dat.charge / numSegs; SpriteBatch sb = Main.spriteBatch; Texture2D midTex = mod.GetTexture("GUI/ChargePanelMid"); Texture2D midETex = mod.GetTexture("GUI/ChargePanelMidE"); Texture2D leftTex = mod.GetTexture("GUI/ChargePanelLeft"); Texture2D rightTex = mod.GetTexture("GUI/ChargePanelRight"); Vector2 leftPos = new Vector2((Main.screenWidth / 2) - (5 * midTex.Width) - (leftTex.Width), 50); sb.Draw(leftTex, leftPos, Color.White); Vector2 inOff = new Vector2(leftTex.Width, 0); Vector2 iOf = new Vector2(midTex.Width, 0); for (int i = 0; i < numSegs; i++) { if (nb > 1f) { sb.Draw(midTex, leftPos + inOff + (i * iOf), Color.White); } else if (nb > 0f) { int offs = (int)(midTex.Width * nb); sb.Draw(midTex, leftPos + inOff + (i * iOf), new Rectangle(0, 0, offs, midTex.Height), Color.White); sb.Draw(midETex, leftPos + inOff + (i * iOf) + new Vector2(offs, 0), new Rectangle(offs, 0, midTex.Width - offs, midTex.Height), Color.White); } else { sb.Draw(midETex, leftPos + inOff + (i * iOf), Color.White); } nb--; } sb.Draw(rightTex, leftPos + inOff + (10 * iOf) - new Vector2(midTex.Width, 10), Color.White); DrawPowerupSelect(dat, (int)leftPos.Y + rightTex.Height + 80); }
private MechData transcribeMech(Mech mech) { MechData mdata = new MechData(); mdata.mechTypeId = UniTable.classGuid[mech.GetType()].ToString(); mdata.mechUnitId = mech.unitId.ToString(); //transcribe abilities mdata.abilityIds = new List <String>(); foreach (ability a in mech.abilities) { mdata.abilityIds.Add(UniTable.classGuid[a.GetType()].ToString()); } //transcribe dynamic attributes mdata.dynamicAtt = new attributes(mech.dynamicAttributes); //transcribe base attributes Debug.Log(mech.baseAtt.maxMovementPoints); mdata.baseAtt = new attributes(mech.baseAtt); Debug.Log(mdata.baseAtt.maxMovementPoints); //transcribe mech class info mdata.parts = new List <partOwnership>(); foreach (KeyValuePair <Part.slot, Part> ownedPart in mech.parts) { mdata.parts.Add(new partOwnership(ownedPart.Key, ownedPart.Value.partId.ToString())); } //transcribe unit class info mdata.movementSpeed = mech.MovementSpeed; mdata.playerNumber = mech.PlayerNumber; mdata.displayName = mech.displayName; return(mdata); }
/// <summary> /// Сохранить данные о механизме /// </summary> public virtual InterObjData GetData() { MechData mData = new MechData(id, activated, transform.position); return(mData); }
public override void PostUpdateRunSpeeds() { //player.mapFullScreen = false; //Main.mapFullscreen = false; Main.mapEnabled = true; player.gravity = ModContent.GetInstance <DimensionManager>().GetGravity(); base.PostUpdateRunSpeeds(); #region gravity stuff if (custGravity && dirToGrav != Vector2.Zero) { Vector2 direction = dirToGrav / dirToGrav.Length(); Vector2 perpDir = new Vector2(-direction.Y, direction.X); float tangVel = Vector2.Dot(gravVelocity, perpDir); float radVel = Vector2.Dot(gravVelocity, direction); float scale; float maxRunFactor = 0.5f; if (!ModContent.GetInstance <GravitySource>().CheckIntersectSurface(player)) { gravVelocity += direction * GRAV_ACCEL; scale = 0.3f; } else { scale = 1f; } if (player.controlRight && !player.controlLeft) { maxRunFactor = 1f; switch (Math.Sign(Vector2.Dot(perpDir, gravVelocity))) { case -1: case 0: gravVelocity += -perpDir * RUN_ACCEL * scale; break; case 1: gravVelocity += -perpDir * RUN_ACCEL * scale * 2f; break; } } else if (player.controlLeft && !player.controlRight) { maxRunFactor = 1f; //player.velocity += dirToGrav * RUN_ACCEL * 0.05f; switch (Math.Sign(Vector2.Dot(perpDir, gravVelocity))) { case 1: case 0: gravVelocity += perpDir * RUN_ACCEL * scale; break; case -1: gravVelocity += perpDir * RUN_ACCEL * scale * 2f; break; } //player.position += new Vector2((float)(Math.Pow(RUN_ACCEL, 2) / Math.Pow(dirToGrav.Length(), 3)), 2 * RUN_ACCEL / dirToGrav.Length()); } gravVelocity -= perpDir * RUN_ACCEL * 0.1f * Math.Sign(Vector2.Dot(gravVelocity, perpDir)); if (Math.Abs(tangVel) > MAX_RUNSPEED * maxRunFactor) { gravVelocity = (Math.Sign(tangVel) * MAX_RUNSPEED * maxRunFactor * perpDir) + (radVel * direction); } if (player.controlJump && ModContent.GetInstance <GravitySource>().CheckIntersectSurface(player) && jumpTicker == 0) { //canJump = false; jumpTicker += 30; gravVelocity += -direction * 7f; } if (jumpTicker > 0) { jumpTicker--; } player.velocity = gravVelocity; } #endregion else { player.maxRunSpeed = 3 + (ampedCounter / 60f); player.runAcceleration = 0.08f + (ampedCounter / 1000f); } if (player.mount.Type == ModContent.GetInstance <Mech>().Type) { MechData dat = (MechData)player.mount._mountSpecificData; if (dat.stasis == true) { player.maxRunSpeed = 0; player.gravity = 100000000; player.jumpSpeedBoost = 0; player.velocity.Y = Math.Max(0, player.velocity.Y); } else if (mechRunSpeed) { player.maxRunSpeed = 8; player.runAcceleration = 0.2f; } } }
public void Init(Game game, BattleHistory battleHistory) { this.game = game; // Copy the history, except for the moves; they'll be applied later. this.history = battleHistory; List <object> moveHistory = battleHistory.moves; this.history.moves = new List <object>(); Scenario scenario = this.history.scenario; BattleMap map = this.history.startingMap; this.mapDisplay.Init(this, map.size); // Build misc objects. { // Let us know when anything on the UI is clicked (and not handled by a button or something). EventTrigger eventTrigger = this.uiRefs.canvas.gameObject.AddComponent <EventTrigger>(); var entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener((data) => { var button = ((PointerEventData)data).button; if (button == PointerEventData.InputButton.Left) { this.MouseEvent(null, MapDisplay.MouseEventType.Click); } else if (button == PointerEventData.InputButton.Right) { this.MouseEvent(null, MapDisplay.MouseEventType.RightClick); } }); eventTrigger.triggers.Add(entry); } // Build map. this.mapSize = map.size; this.tiles = new BattleTile[this.mapSize.x * this.mapSize.y]; TileData baseTileData = GameData.GetTile(map.baseTileName); TileData tileData = baseTileData; this.pathNetwork = new PathNetwork(); for (int y = 0; y < map.size.y; ++y) { for (int x = 0; x < map.size.x; ++x) { var pos = new Vector2i(x, y); tileData = baseTileData; foreach (var o in map.tileOverrides) { if (o.pos == pos) { tileData = GameData.GetTile(o.name); break; } } MapTile mapTile = this.mapDisplay.GetTile(pos); BattleTile newTile = mapTile.gameObject.AddComponent <BattleTile>(); newTile.Init(this, x, y, tileData); this.tiles[x + y * this.mapSize.x] = newTile; } } foreach (BattleTile tile in this.tiles) { for (int n = 0; n < 6; ++n) { BattleTile neighbor = tile.GetNeighbor(n); if (neighbor) { this.pathNetwork.ConnectNodes(tile, neighbor); } } if (tile.data.allowsMovement == false) { this.pathNetwork.SetNodeEnabled(tile, false); } } // Create teams and place mechs. var playerSpawns = new Stack <Vector2i>(); var enemySpawns = new Stack <Vector2i>(); foreach (var e in map.entities) { if (e.name == "PlayerMechSpawn") { playerSpawns.Push(e.pos); } else if (e.name == "EnemyMechSpawn") { enemySpawns.Push(e.pos); } } this.teams = new List <BattleTeam>(); foreach (Scenario.Team teamData in scenario.teams) { BattleTeam team = new BattleTeam(); this.teams.Add(team); team.mechs = new List <BattleMech>(); team.isPlayer = teamData.isPlayer; if (team.isPlayer == false) { team.ai = new BattleTeamAi(team); } team.visibleTiles = new bool[this.tiles.Length]; foreach (Scenario.Mech m in teamData.mechs) { MechData mechData = GameData.GetMech(m.mechName); Vector2i spawnPos = team.isPlayer ? playerSpawns.Pop() : enemySpawns.Pop(); BattleTile tile = this.GetTile(spawnPos); GameObject mechGO = new GameObject(string.Concat("Mech: ", mechData.name)); mechGO.transform.parent = tile.transform; BattleMech mech = mechGO.AddComponent <BattleMech>(); mech.Init(this, mechData); mech.PlaceAtMapTile(tile.mapTile); mech.SetDirection(m.direction); Assert.IsTrue(tile.mech == null); tile.mech = mech; mech.tile = tile; if (team.isPlayer == false) { mech.ai = new BattleMechAi(mech); } this.pathNetwork.SetNodeEnabled(tile, false); team.mechs.Add(mech); mech.team = team; } } this.currentTeamIndex = this.history.scenario.startingTeamIndex; this.currentTeam = this.teams[this.currentTeamIndex]; // UI stuff. this.uiRefs.advanceAiButton.interactable = false; this.uiRefs.tileInfoBorder.SetActive(false); this.uiRefs.mechTab.SetActive(false); this.uiRefs.pilotTab.SetActive(false); this.uiRefs.tileTab.SetActive(false); this.uiRefs.actionsPanel.SetActive(false); Utility.AddButtonClickListener(this.uiRefs.finishTurnButton, this.UnitListButtonPressed); Utility.AddButtonClickListener(this.uiRefs.advanceAiButton, this.UnitListButtonPressed); Utility.AddButtonClickListener(this.uiRefs.mechTabButton, this.TileInfoTabButtonClicked); Utility.AddButtonClickListener(this.uiRefs.pilotTabButton, this.TileInfoTabButtonClicked); Utility.AddButtonClickListener(this.uiRefs.tileTabButton, this.TileInfoTabButtonClicked); Utility.AddButtonClickListener(this.uiRefs.moveButton, this.ActionButtonPressed); Utility.AddButtonClickListener(this.uiRefs.setTargetButton, this.ActionButtonPressed); Utility.AddButtonClickListener(this.uiRefs.fireNowButton, this.ActionButtonPressed); Utility.AddToggleListener(this.uiRefs.fireAutoToggle, this.ActionToggleChanged); Utility.AddButtonHoverListener(this.uiRefs.fireNowButton, this.ActionButtonHoverChanged); this.BringTileTabButtonToFront(this.uiRefs.mechTabButton); this.UpdateRightPanel(); this.apTextOriginalColor = this.uiRefs.apText.color; // Execute any moves to start with. foreach (object o in moveHistory) { this.ExecuteMove(o); } this.currentTeamIndex = battleHistory.currentTeamIndex; this.currentTeam = this.teams[this.currentTeamIndex]; // Start first state. this.UpdateFogOfWar(); if (this.currentTeam.isPlayer) { this.SetState(BattleState.SelectingAction); } else { this.SetState(BattleState.AiControl); } }
/// <summary> /// Сохранить данные о чекпоинте /// </summary> public InterObjData GetData() { MechData chData = new MechData(id, activated, transform.position); return(chData); }
public static MechData GenerateMech(float[,] n, MeshSettings settings, int levelOfDetail) { //Mesh Simplification Increment int msi = (levelOfDetail == 0)?1:levelOfDetail * 2; int borderSize = n.GetLength(0); int meshSize = borderSize - 2 * msi; int meshSizeNoS = borderSize - 2; float topLeftX = (meshSizeNoS - 1) / -2f; float topLeftZ = (meshSizeNoS - 1) / 2f; int verticesPerLine = (meshSize - 1) / msi + 1; MechData mechD = new MechData(borderSize, settings.useFlatShader); int[,] vIndexMap = new int[borderSize, borderSize]; int vMeshIndex = 0; int vBorderIndex = -1; for (int y = 0; y < borderSize; y += msi) { for (int x = 0; x < borderSize; x += msi) { bool isBorderV = y == 0 || y == borderSize - 1 || x == 0 || x == borderSize - 1; if (isBorderV) { vIndexMap[x, y] = vBorderIndex; vBorderIndex--; } else { vIndexMap[x, y] = vMeshIndex; vMeshIndex++; } } } for (int y = 0; y < borderSize; y += msi) { for (int x = 0; x < borderSize; x += msi) { int vIndex = vIndexMap[x, y]; Vector2 percent = new Vector2((x - msi) / (float)meshSize, (y - msi) / (float)meshSize); float height = n[x, y]; Vector3 vPosition = new Vector3((topLeftX + percent.x * meshSizeNoS) * settings.uniformScale, height, (topLeftZ - percent.y * meshSizeNoS) * settings.uniformScale); mechD.AddVertex(vPosition, percent, vIndex); if (x < borderSize - 1 && y < borderSize - 1) { int a = vIndexMap[x, y]; int b = vIndexMap[x + msi, y]; int c = vIndexMap[x, y + msi]; int d = vIndexMap[x + msi, y + msi]; mechD.AddTringele(a, d, c); mechD.AddTringele(d, a, b); } vIndex++; } } mechD.ProcessMesh(); return(mechD); }
public void SpawnUnit(Tile tile, MechData mechData) { SpawnUnit <Mech>(tile, new GameObject().AddComponent <Mech>(), (mech) => mech.Initialize(mechData, Helper)); }
public IEnumerator GenerateEnvironment(HightMap heightMap, MechData meshData, MeshSettings meshSettings, HightMapSettings hightMapSettings, EnvironmentData environmentData, int mapChunkSize, float scale, float min, float max) { int seed; if (environmentData.usingHeightMapSeed) { seed = hightMapSettings.noiseSettings.seed; } else { seed = environmentData.seed; } System.Random prng = new System.Random(seed); bool useFlatSheadedB = false; int flatSheadedChunkSizeIndexB = 0; if (meshSettings.useFlatShader) { flatSheadedChunkSizeIndexB = meshSettings.chunkSizeIndex; useFlatSheadedB = true; meshSettings.chunkSizeIndex = meshSettings.flatSheadedChunkSizeIndex; meshSettings.useFlatShader = false; } for (int i = 0; i < environmentData.types.Length; i++) { panelProcess.setNumer(i + 1 + "/" + environmentData.types.Length); panelProcess.setLabel("Environment "); EnvironmentData.Types now = environmentData.types[i]; float[,] noise = PerlinNoise.GeneratorNoise(mapChunkSize + 2, mapChunkSize + 2, now.noiseData.noiseSettings, Vector2.zero); float[] noisMapEnd = HightMap.ConwertTab(noise, mapChunkSize + 2); int msi = (now.LOD == 0) ? 1 : now.LOD * 2; Vector3 lastPos = Vector3.zero; int len = ((int)(mapChunkSize + 2) / msi) + 1; len = len * len; Vector3[] points = mechDraw.GenerateMech(heightMap.value, meshSettings, now.LOD).vertices; Vector3[] orginalVerticis = meshData.vertices; for (int j = 0; j < len; j++) { Vector3 nowPos = Vector3.zero; if ((positioningMode == PositioningMode.Calculation) || (positioningMode == PositioningMode.BothMode)) { nowPos = orginalVerticis[CalculationPos(points, orginalVerticis, j, len)]; } else { nowPos = points[j]; } panelProcess.setValue((float)j / len); float wynik = map(min, max, 0, 1, nowPos.y); //if (true) if (noisMapEnd[j] < now.curve.Evaluate(wynik)) { if (lastPos != nowPos) { Vector3 randPos = new Vector3(prng.Next(-now.LOD * environmentData.prngPrecision, now.LOD * environmentData.prngPrecision) / environmentData.prngPrecision, 0, prng.Next(-now.LOD * environmentData.prngPrecision, now.LOD * environmentData.prngPrecision) / environmentData.prngPrecision) * now.randPos; float x = 0, y = 0, z = 0; if (now.randRotX) { x = prng.Next(0, 359); } if (now.randRotY) { y = prng.Next(0, 359); } if (now.randRotZ) { z = prng.Next(0, 359); } if ((positioningMode == PositioningMode.Colision) || (positioningMode == PositioningMode.BothMode)) { nowPos.y = ColidePos(nowPos.x + randPos.x, nowPos.z + randPos.z, heightMap.minV, heightMap.maxV) - randPos.y; } Vector3 randRot = new Vector3(x, y, z); lastPos = nowPos; GameObject o = Instantiate(now.Object, (nowPos + randPos) * scale, Quaternion.Euler(now.rotation + randRot)); Transform tObject = o.GetComponent <Transform>() as Transform; tObject.SetParent(parent, true); tObject.localScale = now.scale; if (j % skip == 0) { yield return(null); } } } } } yield return(null); if (useFlatSheadedB) { meshSettings.chunkSizeIndex = flatSheadedChunkSizeIndexB; meshSettings.useFlatShader = true; } panelProcess.setActive(false); }
public override void UseAbility(Player player, Vector2 mousePosition, bool toggleOn) { MechData dat = (MechData)player.mount._mountSpecificData; //Main.NewText(mousePosition); Vector2 dir = Main.MouseWorld - (player.position + new Vector2(0, -165)); Vector2 dir2 = Main.MouseWorld - (player.position + new Vector2(0, -293)); float f = (float)Math.Atan(dir.Y / dir.X); float fl = (float)Math.Atan(dir2.Y / dir2.X); if (dir.X < 0) { f += (float)Math.PI; } if (dir2.X < 0) { fl += (float)Math.PI; } if (fl > MathHelper.ToRadians(30) && fl < Math.PI / 2) { fl = MathHelper.ToRadians(30); } else if (fl >= Math.PI / 2 && fl < MathHelper.ToRadians(150)) { fl = MathHelper.ToRadians(150); } if (!dat.stasis) { dat.gunRotation = MathHelper.Clamp(f, MathHelper.ToRadians(-30), MathHelper.ToRadians(210)); dat.laserRotation = fl; } //Main.NewText(fl); if (Main.mouseLeft && dat.charge > 0.1f && !dat.stasis) { Vector2 line = new Vector2(70f * (float)Math.Cos(dat.gunRotation), 70f * (float)Math.Sin(dat.gunRotation)); float spray = (Main.rand.NextFloat() - 0.5f) * 0.4f; Vector2 bullDir = new Vector2(6f * (float)Math.Cos(dat.gunRotation + spray), 6f * (float)Math.Sin(dat.gunRotation + spray)); dat.UpdateFrame(player.position + new Vector2(0, -175) + line, bullDir); } else { dat.ResetFrame(); } switch (dat.selectedEffect) { case CannonEffects.Base: if (Main.mouseRight) { if (Main.mouseRightRelease) { dat.stasisRegenRate = 0f; } dat.stasis = true; dat.stasisRegenRate += 0.0002f; } else { dat.stasis = false; dat.stasisRegenRate = 0f; } break; case CannonEffects.EnergyBomb: case CannonEffects.StunField: case CannonEffects.Fire: //case CannonEffects.Base: if (Main.mouseRight && Main.mouseRightRelease) { int projType; int chargeLoss; int damage; float velocity; float knockback; Vector2 offs = new Vector2(-10, -345); switch (dat.selectedEffect) { case CannonEffects.EnergyBomb: projType = ModContent.ProjectileType <MechEnergyBomb>(); knockback = 0.2f; damage = 60; chargeLoss = 10; velocity = 8; break; case CannonEffects.Fire: projType = ModContent.ProjectileType <MechFire>(); knockback = 0f; damage = 30; chargeLoss = 2; velocity = 10; offs += new Vector2(-10, 40); break; case CannonEffects.StunField: projType = ModContent.ProjectileType <MechStunField>(); knockback = 0f; damage = 0; chargeLoss = 15; velocity = 10; break; default: throw new InvalidOperationException(); } if (dat.charge < chargeLoss) { break; } Vector2 dirac = Main.MouseWorld - (player.position + new Vector2(0, -293)); float f2 = (float)Math.Atan(dir.Y / dir.X); float lasRot = MathHelper.Clamp(f2, MathHelper.ToRadians(-10), MathHelper.ToRadians(28)); dat.charge = (float)Math.Max(0, dat.charge - chargeLoss); //dirac = new Vector2(1, 0).RotatedBy(lasRot); Vector2 dirc = dir2 / dir2.Length(); Projectile.NewProjectile(player.position + offs + (dirc * 30), dirc * velocity, projType, damage, knockback, Main.myPlayer); } break; case CannonEffects.Laser: if (Main.mouseRight) { //Vector2 dirac = Main.MouseWorld - (player.position + new Vector2(0, -205)); //float f2 = (float)Math.Atan(dir.Y / dir.X); //float lasRot = MathHelper.Clamp(f2, MathHelper.ToRadians(-20), MathHelper.ToRadians(20)); dat.charge = (float)Math.Max(0, dat.charge - 0.5); Vector2 dirv = new Vector2(1, 0).RotatedBy(dat.gunRotation); Vector2 pos = player.position + new Vector2(0, -293) + (20 * dirv); if (!dat.channelLaser) { Projectile.NewProjectile(pos, dirv, ModContent.ProjectileType <MechLaser>(), 40, 0.2f, Main.myPlayer); } dat.channelLaser = true; } else { dat.channelLaser = false; } break; } //if (dat.currEffect != CannonEffects.RunSpeed) mountData.runSpeed = 6f; base.UseAbility(player, mousePosition, toggleOn); }