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); }