public static void Initialize() { ITEM = RegisterEntityBlueprint(new GenericEntityBlueprint <ItemEntity>("item")); BELT = RegisterEntityBlueprint(new GenericEntityBlueprint <Belt>("belt")); BOAT = RegisterEntityBlueprint(new GenericEntityBlueprint <Boat>("boat")); CHEST = RegisterEntityBlueprint(new GenericEntityBlueprint <Chest>("chest")); CHIKEN = RegisterEntityBlueprint(new GenericEntityBlueprint <Chicken>("chiken")); CRAFTING_BENCH = RegisterEntityBlueprint(new GenericEntityBlueprint <Bench>("crafting_bench")); DOG = RegisterEntityBlueprint(new GenericEntityBlueprint <Dog>("dog")); FISH = RegisterEntityBlueprint(new GenericEntityBlueprint <Fish>("fish")); FLOWER = RegisterEntityBlueprint(new GenericEntityBlueprint <Flower>("flower")); FURNACE = RegisterEntityBlueprint(new GenericEntityBlueprint <Furnace>("furnace")); GRASS = RegisterEntityBlueprint(new GenericEntityBlueprint <Grass>("grass")); PLAYER = RegisterEntityBlueprint(new GenericEntityBlueprint <Player>("player")); STAIRES = RegisterEntityBlueprint(new GenericEntityBlueprint <Stairs>("staires")); TNT = RegisterEntityBlueprint(new GenericEntityBlueprint <TNT>("tnt")); TORCH = RegisterEntityBlueprint(new GenericEntityBlueprint <Torch>("torch")); LANTERN = RegisterEntityBlueprint(new GenericEntityBlueprint <Lamp>("lantern")); TREE = RegisterEntityBlueprint(new GenericEntityBlueprint <EntityTree>("tree")); ZOMBIE = RegisterEntityBlueprint(new GenericEntityBlueprint <Zombie>("zombie")); XPORB = RegisterEntityBlueprint(new GenericEntityBlueprint <XpOrb>("xporb")); GROUPE_CREATURE = new Groupe <EntityBlueprint>("creature", CHIKEN, FISH, PLAYER, ZOMBIE); GROUPE_TREE = new Groupe <EntityBlueprint>("tree", TREE); GROUPE_SAVE_EXCUDED = new Groupe <EntityBlueprint>("save_excluded", PLAYER); }
public void LoadBlueprint(EntityBlueprint blueprint, DroneSpawnData data) { shellImage.sprite = ResourceManager.GetAsset <Sprite>(blueprint.coreShellSpriteID); if (shellImage.sprite) { shellImage.enabled = true; shellImage.color = FactionManager.GetFactionColor(0); shellImage.rectTransform.sizeDelta = shellImage.sprite.bounds.size * 100; shellImage.type = Image.Type.Sliced; // orient shell image so relative center stays the same regardless of shell tier shellImage.rectTransform.anchoredPosition = -shellImage.sprite.pivot + shellImage.rectTransform.sizeDelta / 2; } else { shellImage.enabled = false; } coreImage.rectTransform.anchoredPosition = -shellImage.rectTransform.anchoredPosition; coreImage.sprite = ResourceManager.GetAsset <Sprite>(blueprint.coreSpriteID); if (coreImage.sprite) { coreImage.enabled = true; coreImage.material = ResourceManager.GetAsset <Material>("material_color_swap"); coreImage.color = FactionManager.GetFactionColor(0); coreImage.preserveAspect = true; coreImage.type = Image.Type.Sliced; coreImage.rectTransform.sizeDelta = coreImage.sprite.bounds.size * 100; } else { coreImage.enabled = false; } if (data.type == DroneType.Mini) { miniDroneShooter.gameObject.SetActive(true); miniDroneShooter.enabled = true; miniDroneShooter.sprite = ResourceManager.GetAsset <Sprite>(AbilityUtilities.GetShooterByID(6)); miniDroneShooter.color = FactionManager.GetFactionColor(0); miniDroneShooter.rectTransform.sizeDelta = miniDroneShooter.sprite.bounds.size * 100; miniDroneShooter.type = Image.Type.Sliced; } else { miniDroneShooter.gameObject.SetActive(false); miniDroneShooter.enabled = false; } foreach (EntityBlueprint.PartInfo part in blueprint.parts) { var p = Instantiate(partPrefab, cursorScript.transform.parent).GetComponent <ShipBuilderPart>(); p.cursorScript = cursorScript; cursorScript.parts.Add(p); p.info = part; p.SetLastValidPos(part.location); p.isInChain = true; p.validPos = true; p.InitializeMode(BuilderMode.Workshop); } }
public void InitializeBuildPhase(EntityBlueprint blueprint, EntityBlueprint.PartInfo currentPart, DroneSpawnData data) { searcherString = ""; displayingTypes = new bool[] { true, false, true, true, true }; this.currentData = data; this.currentPart = currentPart; selectionPhaseParent.SetActive(false); buildPhaseParent.SetActive(true); LoadBlueprint(blueprint, data); builderPartDict = new Dictionary <EntityBlueprint.PartInfo, ShipBuilderInventoryScript>(); contentsArray = new Transform[] { smallBuilderContents, mediumBuilderContents, largeBuilderContents }; contentTexts = new GameObject[] { smallBuilderText, mediumBuilderText, largeBuilderText }; foreach (GameObject obj in contentTexts) { obj.SetActive(false); } foreach (EntityBlueprint.PartInfo part in player.GetInventory()) { if (part.abilityID != 10 && ResourceManager.GetAsset <PartBlueprint>(part.partID).size == 0) { AddPart(part); } } GetComponentInChildren <ShipBuilderPartDisplay>().Initialize(this); phase = DroneWorkshopPhase.BuildPhase; cursorScript.gameObject.SetActive(true); cursorScript.SetMode(BuilderMode.Workshop); }
public static void Initialize() { ITEM = RegisterEntityBlueprint(new GenericEntityBlueprint <ItemEntity>("item")); BELT = RegisterEntityBlueprint(new GenericEntityBlueprint <Belt>("belt")); CHEST = RegisterEntityBlueprint(new GenericEntityBlueprint <Chest>("chest")); CHIKEN = RegisterEntityBlueprint(new GenericEntityBlueprint <Chicken>("chiken")); CRAFTING_BENCH = RegisterEntityBlueprint(new GenericEntityBlueprint <CraftingBench>("crafting_bench")); FISH = RegisterEntityBlueprint(new GenericEntityBlueprint <Fish>("fish")); FLOWER = RegisterEntityBlueprint(new GenericEntityBlueprint <Flower>("flower")); FURNACE = RegisterEntityBlueprint(new GenericEntityBlueprint <Furnace>("furnace")); GRASS = RegisterEntityBlueprint(new GenericEntityBlueprint <Grass>("grass")); PLAYER = RegisterEntityBlueprint(new GenericEntityBlueprint <Player>("player")); STAIRES = RegisterEntityBlueprint(new GenericEntityBlueprint <Stairs>("staires")); TNT = RegisterEntityBlueprint(new GenericEntityBlueprint <TNT>("tnt")); TORCH = RegisterEntityBlueprint(new GenericEntityBlueprint <Torch>("torch")); TREE = RegisterEntityBlueprint(new GenericEntityBlueprint <EntityTree>("tree")); ZOMBIE = RegisterEntityBlueprint(new GenericEntityBlueprint <Zombie>("zombie")); GROUPE_CREATURE = new BlueprintGroupe <EntityBlueprint>("creature") { Members = { CHIKEN, FISH, PLAYER, ZOMBIE } }; GROUPE_TREE = new BlueprintGroupe <EntityBlueprint>("tree") { Members = { TREE } }; GROUPE_SAVE_EXCUDED = new BlueprintGroupe <EntityBlueprint>("save_excluded") { Members = { PLAYER } }; }
public Entity AddEntityAt(EntityBlueprint b, int tx, int ty, float offX = 0f, float offY = 0f) { var entity = b.Construct(); AddEntityAt(entity, tx, ty, offX, offY); return(entity); }
public override void OnPointerDown(PointerEventData eventData) { if (Input.GetKey(KeyCode.LeftShift)) { #if UNITY_EDITOR #endif } if (count > 0) { var builderPart = InstantiatePart(); DecrementCount(); if (Input.GetKey(KeyCode.LeftShift)) { if (mode == BuilderMode.Yard && cursor.builder.GetMode() == BuilderMode.Trader) { cursor.builder.DispatchPart(builderPart, ShipBuilder.TransferMode.Sell); return; } else if (mode == BuilderMode.Trader) { cursor.buildCost += EntityBlueprint.GetPartValue(builderPart.info); cursor.builder.DispatchPart(builderPart, ShipBuilder.TransferMode.Buy); return; } } ShipBuilderPart symmetryPart = count > 0 && cursor.symmetryMode != ShipBuilderCursorScript.SymmetryMode.Off ? InstantiatePart() : null; if (symmetryPart) { //if(cursor.symmetryMode == ShipBuilderCursorScript.SymmetryMode.X) symmetryPart.info.mirrored = !builderPart.info.mirrored; if (cursor.symmetryMode == ShipBuilderCursorScript.SymmetryMode.Y) { symmetryPart.info.rotation = 180; } } cursor.GrabPart(builderPart, symmetryPart); if (symmetryPart) { DecrementCount(); } cursor.buildValue += EntityBlueprint.GetPartValue(part); if (symmetryPart) { cursor.buildValue += EntityBlueprint.GetPartValue(part); } if (mode == BuilderMode.Trader) { cursor.buildCost += EntityBlueprint.GetPartValue(part); if (symmetryPart) { cursor.buildCost += EntityBlueprint.GetPartValue(part); } } } }
void Start() { origPos = saveName.rectTransform.anchoredPosition.x; EntityBlueprint print = ScriptableObject.CreateInstance <EntityBlueprint>(); JsonUtility.FromJsonOverwrite(save.currentPlayerBlueprint, print); shellImage.sprite = ResourceManager.GetAsset <Sprite>(print.coreShellSpriteID); shellImage.rectTransform.sizeDelta = shellImage.sprite.bounds.size * 50; coreImage.material = ResourceManager.GetAsset <Material>("material_color_swap"); shellImage.color = coreImage.color = FactionManager.GetFactionColor(0); shellImage.rectTransform.anchoredPosition = new Vector2(shellImage.rectTransform.anchoredPosition.x, (shellImage.rectTransform.sizeDelta.y - (shellImage.sprite.pivot).y) / 2); saveName.text = save.name; episodeNumber.text = $"Episode: {Mathf.Max(1, save.episode)}"; version.text = "Version: " + save.version; if (save.version.Contains("Prototype") || save.version.Contains("Alpha 0.0.0")) { version.color = Color.red; version.text += " - Unsupported Version!"; } if (SaveMenuHandler.migrationVersions.Exists((v) => save.version == v)) { version.color = 0.5F * Color.green + Color.red; version.text += " - Click save to attempt migration"; } timePlayed.text = string.Format("Time Played: {0:D2}:{1:D2}", (int)save.timePlayed / 60, (int)save.timePlayed % 60); }
/// <summary> /// The entry point of the game, where it is decleraded and started. /// </summary> public void Main() { ///////////////////////// // Initialization // ///////////////////////// Ludum.Initialize(); // Settings Ludum.Settings.Fullscreen = false; Ludum.Settings.AssetsDirectory = "GameContents"; ///////////////////////// // Blueprints // ///////////////////////// // T-Rex EntityBlueprint tyrannosaurus = Ludum.Blueprints.CreateEntityBlueprint("TRex"); tyrannosaurus.AddComponent <Sprite> ().Set(filename: "trexSprite"); tyrannosaurus.AddComponent <Body> ().SetPosition(x: 0, y: 50); tyrannosaurus.AddComponent <Moveable> (); // Ape EntityBlueprint greatApe = Ludum.Blueprints.CreateEntityBlueprint("GreatApe"); greatApe.AddComponent <Sprite> ().Set(filename: "apeSprite"); greatApe.AddComponent <Body> ().SetPosition(x: 200, y: 50); // Scene Controller // EntityBlueprint controller = Ludum.Blueprints.CreateEntityBlueprint ("Controller"); // controller.AddComponent<ChangeScene>().SetScene("arena"); // controller.AddComponent<Sprite>().Set("logo"); // controller.AddComponent<Body>().SetPosition(x: 200, y: 50); ///////////////////////// // Scenes // ///////////////////////// // Arena Scene arena = Ludum.Scenes.CreateScene("arena"); arena.CreateEntity(greatApe); arena.CreateEntity(tyrannosaurus); // Startscene // Scene startscene = Ludum.Scenes.CreateScene("start"); // startscene.BackgroundColor = Color.Black; // startscene.CreateEntity(controller); ///////////////////////// // Start the game // ///////////////////////// // Start the game Ludum.Start(scene: arena); }
void DestroyableObjectComponent_OnDyingAnimationFinished(object sender, EventArgs e) { var entity = ((DyingComponent)sender).Parent; //Drops item if (DropsItem && DroppableItems.Count != 0) { Random rand = new Random(); float chance = (float)rand.NextDouble(); float droprate = DropRate; float floor = 0f; string item = ""; foreach (string i in DroppableItems) { if (floor < chance && chance <= (droprate + floor)) { item = i; break; } floor += droprate; droprate /= DropCoefficient; } if (!string.IsNullOrEmpty(item)) { var powerup = EntityBlueprint.GetBlueprint(item).CreateEntity(); powerup.Size = new Vector2(16, 16); powerup.Position = new Vector2(Parent.Location.Center.X, Parent.Location.Top); entity.Scene.AddEntity(powerup); } } }
protected override void Start() { data = DroneWorkshop.ParseDronePart(part); blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); JsonUtility.FromJsonOverwrite(data.drone, blueprint); base.Start(); }
public void OnPointerClick(PointerEventData eventData) { if (Input.GetKey(KeyCode.LeftShift)) { ClearPreset(); return; } if (!valid) { return; // allow user to left shift out blueprint so return after that } // TODO: check if adding a part back into your inventory validates the preset if (!blueprint && (builder.reconstructStatus == ShipBuilder.ReconstructButtonStatus.Valid)) { blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); blueprint.coreShellSpriteID = player.blueprint.coreShellSpriteID; blueprint.coreSpriteID = player.blueprint.coreSpriteID; blueprint.parts = new List <EntityBlueprint.PartInfo>(); foreach (ShipBuilderPart part in cursorScript.parts) { if (!part.isInChain || !part.validPos) { blueprint = null; return; } blueprint.parts.Add(part.info); } if (player.cursave.presetBlueprints == null || (player.cursave.presetBlueprints != null && player.cursave.presetBlueprints.Length < 5)) { player.cursave.presetBlueprints = new string[5]; } player.cursave.presetBlueprints[number - 1] = JsonUtility.ToJson(blueprint); } else if (blueprint) { cursorScript.ClearAllParts(); foreach (EntityBlueprint.PartInfo info in blueprint.parts) { if (!builder.DecrementPartButton(ShipBuilder.CullSpatialValues(info))) { // cursorScript.ClearAllParts(); builder.CloseUI(false); return; } } var x = new EntityBlueprint.PartInfo[blueprint.parts.Count]; blueprint.parts.CopyTo(x); player.blueprint.parts = new List <EntityBlueprint.PartInfo>(x); builder.CloseUI(true); OnPointerExit(null); player.Rebuild(); } }
public static PlayerSave CreateSave(string name, string checkpointName = null, string resourcePath = "") { string currentVersion = VersionNumberScript.version; PlayerSave save = new PlayerSave(); save.name = name; save.timePlayed = 0; save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); save.sectorsSeen = new List <string>(); save.missions = new List <Mission>(); // this section contains default information for a new save. Edit this to change how the default save // is created. EntityBlueprint blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); blueprint.name = "Player Save Blueprint"; blueprint.baseRegen = new float[] { 60, 0, 60 }; blueprint.shellHealth = new float[] { 1000, 250, 500 }; blueprint.parts = new List <EntityBlueprint.PartInfo>(); blueprint.coreSpriteID = "core1_light"; blueprint.coreShellSpriteID = "core1_shell"; save.currentPlayerBlueprint = JsonUtility.ToJson(blueprint); save.abilityCaps = new int[] { 10, 3, 10, 10 }; save.shards = 0; save.version = currentVersion; save.resourcePath = resourcePath; save.abilityHotkeys = new AbilityHotkeyStruct(); File.WriteAllText(Application.persistentDataPath + "\\Saves" + "\\" + name, JsonUtility.ToJson(save)); return(save); }
/// <summary> /// Loads a new Entity that can be used for the player. /// </summary> public static Entity LoadPlayerEntity() { // TODO: Allow support for different 'classes' by just using different blueprints. var Blueprint = EntityBlueprint.GetBlueprint("Player"); var PlayerEntity = Blueprint.CreateEntity(); PlayerEntity.Size = new Vector2(36, 36); return(PlayerEntity); }
public void DisplayPartInfo(EntityBlueprint.PartInfo info) { if (info.abilityID != 0) { if (info.tier != 0) { abilityTier.gameObject.SetActive(true); abilityTier.sprite = ResourceManager.GetAsset <Sprite>("AbilityTier" + info.tier); if (abilityTier.sprite) { abilityTier.rectTransform.sizeDelta = abilityTier.sprite.bounds.size * 20; } abilityTier.color = new Color(1, 1, 1, 0.4F); } else { abilityTier.gameObject.SetActive(false); } abilityImage.sprite = AbilityUtilities.GetAbilityImageByID(info.abilityID, info.secondaryData); abilityImage.gameObject.SetActive(true); abilityText.text = AbilityUtilities.GetAbilityNameByID(info.abilityID, info.secondaryData) + (info.tier > 0 ? " " + info.tier : ""); abilityText.gameObject.SetActive(true); abilityBox.gameObject.SetActive(true); string description = ""; description += AbilityUtilities.GetAbilityNameByID(info.abilityID, info.secondaryData) + (info.tier > 0 ? " " + info.tier : "") + "\n"; description += AbilityUtilities.GetDescriptionByID(info.abilityID, info.tier, info.secondaryData); buttonScript.abilityInfo = description; } else { abilityTier.gameObject.SetActive(false); abilityBox.gameObject.SetActive(false); abilityImage.gameObject.SetActive(false); abilityText.gameObject.SetActive(false); } image.gameObject.SetActive(true); partName.gameObject.SetActive(true); partStats.gameObject.SetActive(true); string partID = info.partID; partName.text = partID; var blueprint = ResourceManager.GetAsset <PartBlueprint>(partID); float mass = blueprint.mass; float health = blueprint.health; int value = EntityBlueprint.GetPartValue(info); partStats.text = $"PART SHELL: {health / 2}\nPART CORE: {health / 4}\nPART WEIGHT: {mass * Entity.weightMultiplier}\nPART VALUE: \n{value} CREDITS"; image.sprite = ResourceManager.GetAsset <Sprite>(partID + "_sprite"); image.rectTransform.sizeDelta = image.sprite.bounds.size * 50; image.color = info.shiny ? FactionManager.GetFactionShinyColor(0) : FactionManager.GetFactionColor(0); }
void SpawnAdditionalEntity(string flagName) { Vector2 coords = coordinates; if (!useCoordinates) { for (int i = 0; i < AIData.flags.Count; i++) { if (AIData.flags[i].name == flagName) { coords = AIData.flags[i].transform.position; if (DevConsoleScript.fullLog) { Debug.Log(coords); } break; } } } EntityBlueprint blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); try { JsonUtility.FromJsonOverwrite(this.blueprint, blueprint); } catch (System.Exception) { Debug.Log("Could not parse blueprint value as JSON. Now attempting to fetch blueprint through the Resource Manager."); blueprint = ResourceManager.GetAsset <EntityBlueprint>(this.blueprint); } if (blueprint) { Sector.LevelEntity entityData = new Sector.LevelEntity { faction = faction, name = entityName, position = coords, ID = issueID ? entityID : "" }; var entity = SectorManager.instance.SpawnEntity(blueprint, entityData); if (DevConsoleScript.fullLog) { Debug.Log(entity.transform.position + " " + entity.spawnPoint); } entity.name = entityName; } else { Debug.LogWarning("Blueprint not found!"); } }
public void Init() { ID = AbilityID.SpawnDrone; cooldownDuration = spawnData.cooldown; chargeDuration = spawnData.delay; activeDuration = spawnData.delay + 0.1f; energyCost = spawnData.energyCost; // create blueprint from string json in spawn data blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); JsonUtility.FromJsonOverwrite(spawnData.drone, blueprint); }
// Wrapper for assembling core protected void SetUpParts(EntityBlueprint blueprint) { if (blueprint != null && blueprint.parts != null) { ResetHealths(); for (int i = 0; i < blueprint.parts.Count; i++) { SetUpPart(blueprint.parts[i]); } } }
public int GetBuildValue() { var value = 0; foreach (var part in blueprint.parts) { value += EntityBlueprint.GetPartValue(part); } return(value); }
public void ClearPreset() { if (player.cursave.presetBlueprints != null) { player.cursave.presetBlueprints[number - 1] = null; } blueprint = null; valid = true; currentPartHandler.SetActive(true); displayHandler.ClearDisplay(); }
void OnEnable() { compactMode = Screen.width == 1024; buildCost = 0; currentAbilities = new List <Ability>(); grid.anchoredPosition = Vector2.zero; buildValue = 0; foreach (ShipBuilderPart part in parts) { buildValue += EntityBlueprint.GetPartValue(part.info); } }
public static EntityBlueprint RegisterEntityBlueprint(EntityBlueprint blueprint) { if (_blueprintLibrary.ContainsKey(blueprint.Name)) { _blueprintLibrary[blueprint.Name] = blueprint; } else { _blueprintLibrary.Add(blueprint.Name, blueprint); } return(blueprint); }
private void DropWeapon(string weaponToDrop, float launchModifier = 1f) { var mc = this.GetDependency <MovementComponent>(); var scene = Parent.Scene; var oldWeapon = EntityBlueprint.GetBlueprint(weaponToDrop).CreateEntity(); oldWeapon.Position = new Vector2(Parent.Position.X + -CorvusExtensions.GetSign(mc.CurrentDirection) * (Parent.Size.X + 5), Parent.Position.Y - Parent.Size.Y - 5); oldWeapon.Size = new Vector2(22, 22); scene.AddEntity(oldWeapon); Random rand = new Random(); float rMod = (float)rand.Next(20, 50); var pc = oldWeapon.GetComponent <PhysicsComponent>(); pc.Velocity = new Vector2(-CorvusExtensions.GetSign(mc.CurrentDirection) * 225f * launchModifier + rMod, -325f * launchModifier + rMod); }
// Use this for initialization public void Initialize() { image = GetComponent <Image>(); text = GetComponentInChildren <Text>(); blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); if (player.cursave.presetBlueprints != null && player.cursave.presetBlueprints.Length >= number && player.cursave.presetBlueprints[number - 1] != null) { JsonUtility.FromJsonOverwrite(player.cursave.presetBlueprints[number - 1], blueprint); } if (blueprint.parts == null) { blueprint = null; } initialized = true; }
private void GenerateCoinEntity(string coinName, float xmod) { var c = EntityBlueprint.GetBlueprint(coinName).CreateEntity(); c.Size = new Vector2(12, 12); c.Position = new Vector2(Parent.Location.Center.X, Parent.Location.Top); Parent.Scene.AddEntity(c); Random rand = new Random(); var pc = c.GetComponent <PhysicsComponent>(); pc.HorizontalDragCoefficient = 0.01f; pc.GravityCoefficient = 0.2f; var mc = this.GetDependency <MovementComponent>(); pc.VelocityX = ((mc == null) ? ((rand.Next(0, 5) <= 2) ? 1 : -1) : -CorvusExtensions.GetSign(mc.CurrentDirection)) * (50f * xmod); }
private static Entity ParseEntity(XmlNode ObjectNode) { float Width = float.Parse(ObjectNode.Attributes["width"].Value); float Height = float.Parse(ObjectNode.Attributes["height"].Value); float X = float.Parse(ObjectNode.Attributes["x"].Value); float Y = float.Parse(ObjectNode.Attributes["y"].Value); string BlueprintName = ObjectNode.Attributes["type"].Value.Trim(); string EntityName = ObjectNode.Attributes["name"] == null ? null : ObjectNode.Attributes["name"].Value.Trim(); EntityBlueprint Blueprint = EntityBlueprint.GetBlueprint(BlueprintName); Entity Entity = Blueprint.CreateEntity(); if (!String.IsNullOrWhiteSpace(EntityName)) { Entity.Name = EntityName; } Entity.Position = new Vector2(X, Y); Entity.Size = new Vector2(Width, Height); foreach (XmlNode PropertiesNode in ObjectNode.SelectNodes("properties")) { foreach (XmlNode PropertyNode in PropertiesNode.SelectNodes("property")) { string Name = PropertyNode.Attributes["name"].Value.Trim(); // So, this is quite a hack. // Tiled doesn't allow us to re-order properties; it's all alphabetical. // So we just support sticking a # in front of the property to make it go to the top of the list, and then ignore that #. while (Name.FirstOrDefault() == '#') { Name = Name.Substring(1); } string Value = PropertyNode.Attributes["value"].Value.Trim(); string[] NamePropertySplit = Name.Split('.'); if (NamePropertySplit.Length != 2) { throw new FormatException("Expected object property name to be in the format of 'PathComponent.Nodes'."); } string ComponentName = NamePropertySplit[0].Trim(); string PropertyName = NamePropertySplit[1].Trim(); ComponentArgument Argument = ComponentArgument.Parse(Value).Single(); ComponentProperty ParsedProperty = new ComponentProperty(ComponentName, PropertyName, Argument); var Component = Entity.Components[ComponentName]; ParsedProperty.ApplyValue(Component); } } return(Entity); }
public override void AssignDisplay(EntityBlueprint blueprint, DroneSpawnData data, int faction = 0) { base.AssignDisplay(blueprint, data); statsDisplay.gameObject.SetActive(true); droneDesc.enabled = true; droneDesc.text = ("DRONE TYPE: " + data.type).ToUpper() + "\nUNIQUE CHARACTERISTIC:\n" + "<color=lime>" + DroneUtilities.GetUniqueCharacteristic(data.type) + "</color>" + "\nPART LIMIT: " + DroneUtilities.GetPartLimit(data.type) + "\nSPAWNING COOLDOWN: " + DroneUtilities.GetCooldown(data.type) + "\nSPAWNING DELAY: " + DroneUtilities.GetDelay(data.type) + "\nSPAWNING ENERGY COST: " + DroneUtilities.GetEnergyCost(data.type); foreach (DisplayPart part in parts) { buildValue += EntityBlueprint.GetPartValue(part.info); } }
public void DispatchPart(ShipBuilderPart part, ShipBuilder.TransferMode mode) { var culledInfo = ShipBuilder.CullSpatialValues(part.info); if (!builderPartDict.ContainsKey(culledInfo)) { int size = ResourceManager.GetAsset <PartBlueprint>(part.info.partID).size; ShipBuilderInventoryScript builderPartDictInvButton = Instantiate(buttonPrefab, contentsArray[size]).GetComponent <ShipBuilderInventoryScript>(); builderPartDict.Add(culledInfo, builderPartDictInvButton); contentTexts[size].SetActive(true); builderPartDict[culledInfo].part = culledInfo; builderPartDict[culledInfo].cursor = cursorScript; } builderPartDict[culledInfo].IncrementCount(); cursorScript.buildValue -= EntityBlueprint.GetPartValue(part.info); cursorScript.parts.Remove(part); Destroy(part.gameObject); }
public override void OnPointerDown(PointerEventData eventData) { if (Input.GetKey(KeyCode.LeftShift)) { #if UNITY_EDITOR Debug.Log(part.secondaryData); #endif } if (count > 0) { var builderPart = Instantiate(SBPrefab, cursor.transform.parent).GetComponent <ShipBuilderPart>(); builderPart.info = part; builderPart.cursorScript = cursor; builderPart.mode = mode; cursor.parts.Add(builderPart); cursor.GrabPart(builderPart); count--; cursor.buildValue += EntityBlueprint.GetPartValue(part); if (mode == BuilderMode.Trader) { cursor.buildCost += EntityBlueprint.GetPartValue(part); } if (Input.GetKey(KeyCode.LeftShift)) { if (mode == BuilderMode.Yard && cursor.builder.GetMode() == BuilderMode.Trader) { cursor.builder.DispatchPart(builderPart, ShipBuilder.TransferMode.Sell); } else if (mode == BuilderMode.Trader) { cursor.builder.DispatchPart(builderPart, ShipBuilder.TransferMode.Buy); } } } }
public override void AssignDisplay(EntityBlueprint blueprint, DroneSpawnData data, int faction = 0) { base.AssignDisplay(blueprint, data); statsDisplay.gameObject.SetActive(true); droneDesc.enabled = true; string description = string.Join("\n", new string[] { ($"DRONE TYPE: {data.type}").ToUpper(), "UNIQUE CHARACTERISTIC:", $"<color=lime>{DroneUtilities.GetUniqueCharacteristic(data.type)}</color>", $"PART LIMIT: {DroneUtilities.GetPartLimit(data.type)}", $"SPAWNING COOLDOWN: {DroneUtilities.GetCooldown(data.type)}", $"SPAWNING DELAY: {DroneUtilities.GetDelay(data.type)}", $"SPAWNING ENERGY COST: {DroneUtilities.GetEnergyCost(data.type)}", }); droneDesc.text = description; foreach (DisplayPart part in parts) { buildValue += EntityBlueprint.GetPartValue(part.info); } }
public override int Traverse() { count = Mathf.Max(1, count); if (issueID) { Vector2 coords = coordinates; if (!useCoordinates) { for (int i = 0; i < AIData.flags.Count; i++) { if (AIData.flags[i].name == flagName) { coords = AIData.flags[i].transform.position; break; } } } foreach (var data in SectorManager.instance.characters) { if (data.ID == entityID) { Debug.Log("Spawn Entity ID given matches with a character name! Spawning character..."); foreach (var oj in AIData.entities) { if (oj && oj.ID == data.ID) { Debug.Log("Character already found. Not spawning."); if (forceCharacterTeleport) { (oj as AirCraft).Warp(coords); // hack for now, all the characters are AirCrafts so this should be fine. } return(0); } } var characterBlueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); JsonUtility.FromJsonOverwrite(data.blueprintJSON, characterBlueprint); Sector.LevelEntity entityData = new Sector.LevelEntity { faction = data.faction, name = data.name, position = coords, ID = data.ID }; SectorManager.instance.SpawnEntity(characterBlueprint, entityData); return(0); } } Debug.Log($"Spawn Entity ID ( {entityID} ) does not correspond with a character. Performing normal operations."); } EntityBlueprint blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); try { JsonUtility.FromJsonOverwrite(this.blueprint, blueprint); } catch (System.Exception) { Debug.Log("Could not parse blueprint value as JSON. Now attempting to fetch blueprint through the Resource Manager."); blueprint = ResourceManager.GetAsset <EntityBlueprint>(this.blueprint); } for (int i = 0; i < count; i++) { SpawnAdditionalEntity(flagName); } if (additionalFlags != null) { for (int i = 0; i < additionalFlags.Count; i++) { for (int j = 0; j < additionalCounts[i]; j++) { SpawnAdditionalEntity(additionalFlags[i]); } } } return(0); }