public static StaticObject SpawnObject(ObjectInfo objectInfo, Vector3 pos, bool fit = false, Transform parent = null) { if (fit) { pos = Iso.MapToIso(pos); if (!CollisionMap.Fit(pos, out pos, objectInfo.sizeX)) { return(null); } pos = Iso.MapToWorld(pos); } var gameObject = new GameObject(objectInfo.description); gameObject.transform.position = pos; var staticObject = gameObject.AddComponent <StaticObject>(); staticObject.objectInfo = objectInfo; staticObject.title = objectInfo.name; gameObject.transform.SetParent(parent, true); return(staticObject); }
public void InstantMove(Vector2 target) { Vector3 newPos; if (CollisionMap.Fit(target, out newPos, size)) { CollisionMap.Move(iso.pos, newPos, size, gameObject); iso.pos = newPos; _moving = false; } else { Debug.LogWarning("Can't move character - doesn't fit"); } }
public static Pickup Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0) { position = Iso.MapToIso(position); if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item)) { Debug.LogError("Can't fit pickup"); return(null); } position = Iso.MapToWorld(position); var gameObject = new GameObject(name); gameObject.transform.position = position; var spritesheet = DC6.Load(flippyFile); var animator = gameObject.AddComponent <SpriteAnimator>(); animator.sprites = spritesheet.GetSprites(dir); animator.loop = false; var pickup = gameObject.AddComponent <Pickup>(); pickup.title = title; return(pickup); }
public static Loot Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0) { position = Iso.MapToIso(position); if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item)) { Debug.LogError("Can't fit loot"); return(null); } position = Iso.MapToWorld(position); var gameObject = new GameObject(name); gameObject.transform.position = position; var palette = Palette.GetPalette(PaletteType.Act1); var spritesheet = DC6.Load(flippyFile, palette); var animator = gameObject.AddComponent <SpriteAnimator>(); animator.SetSprites(spritesheet.GetSprites(dir)); animator.loop = false; var loot = gameObject.AddComponent <Loot>(); loot.title = title; return(loot); }
public static Character SpawnMonster(MonStat monStat, Vector3 pos, Transform parent = null) { pos = Iso.MapToIso(pos); if (!CollisionMap.Fit(pos, out pos, monStat.ext.sizeX)) { return(null); } pos = Iso.MapToWorld(pos); var monster = new GameObject(monStat.nameStr); monster.transform.SetParent(parent); monster.transform.position = pos; var character = monster.AddComponent <Character>(); character.monStat = monStat; character.title = monStat.name; character.basePath = @"data\global\monsters"; character.token = monStat.code; character.weaponClass = monStat.ext.baseWeaponClass; character.run = false; character.walkSpeed = monStat.speed; character.runSpeed = monStat.runSpeed; character.size = monStat.ext.sizeX; var monLvl = MonLvl.Find(monStat.level[0]); if (monLvl != null && !monStat.noRatio) { character.health = Random.Range(monLvl.hp[0] * monStat.stats[0].minHP, monLvl.hp[0] * monStat.stats[0].maxHP + 1) / 100; } else { character.health = Random.Range(monStat.stats[0].minHP, monStat.stats[0].maxHP + 1); } character.maxHealth = character.health; var animator = character.GetComponent <COFAnimator>(); animator.equip = new string[monStat.ext.gearVariants.Length]; for (int i = 0; i < animator.equip.Length; ++i) { var variants = monStat.ext.gearVariants[i]; if (variants == null) { continue; } animator.equip[i] = variants[Random.Range(0, variants.Length)]; } if (monStat.ai == "Npc") { monster.AddComponent <NpcController>(); } else if (monStat.ai != "Idle" && monStat.ai != "NpcStationary") { monster.AddComponent <MonsterController>(); } var body = monster.AddComponent <Rigidbody2D>(); body.isKinematic = true; var collider = monster.AddComponent <CircleCollider2D>(); collider.radius = monStat.ext.sizeX * Iso.tileSizeY; return(character); }
public static Unit SpawnMonster(MonStat monStat, Vector3 pos, Transform parent = null, Unit summoner = null) { pos = Iso.MapToIso(pos); if (!CollisionMap.Fit(pos, out pos, monStat.ext.sizeX)) { return(null); } var monster = new GameObject(monStat.nameStr); monster.transform.SetParent(parent); monster.transform.position = Iso.MapToWorld(pos); CollisionMap.Move(pos, pos, monStat.ext.sizeX, monster); var unit = monster.AddComponent <Unit>(); unit.monStat = monStat; unit.title = monStat.name; unit.basePath = @"data\global\monsters"; unit.token = monStat.code; unit.weaponClass = monStat.ext.baseWeaponClass; unit.run = false; unit.walkSpeed = monStat.speed; unit.runSpeed = monStat.runSpeed; unit.size = monStat.ext.sizeX; unit.killable = monStat.killable; var monLvl = MonLvl.Find(monStat.level[0]); if (monLvl != null && !monStat.noRatio) { unit.health = Random.Range(monLvl.hp[0] * monStat.stats[0].minHP, monLvl.hp[0] * monStat.stats[0].maxHP + 1) / 100; } else { unit.health = Random.Range(monStat.stats[0].minHP, monStat.stats[0].maxHP + 1); } unit.maxHealth = unit.health; var animator = unit.GetComponent <COFAnimator>(); animator.equip = new string[monStat.ext.gearVariants.Length]; for (int i = 0; i < animator.equip.Length; ++i) { var variants = monStat.ext.gearVariants[i]; if (variants == null) { continue; } animator.equip[i] = variants[Random.Range(0, variants.Length)]; } if (summoner != null) { unit.party = summoner.party; var petController = monster.AddComponent <PetController>(); petController.owner = summoner; } else if (monStat.ai == "Npc" || monStat.ai == "Towner" || monStat.ai == "Vendor" || monStat.ai == "Hireable") { unit.party = Party.Good; monster.AddComponent <NpcController>(); } else if (monStat.ai != "Idle" && monStat.ai != "NpcStationary") { unit.party = Party.Evil; monster.AddComponent <MonsterController>(); } var body = monster.AddComponent <Rigidbody2D>(); body.isKinematic = true; var collider = monster.AddComponent <CircleCollider2D>(); collider.radius = monStat.ext.sizeX * Iso.tileSizeY; return(unit); }