being.go 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. package world
  2. import (
  3. "fmt"
  4. "math"
  5. "strings"
  6. "gitlab.com/beoran/woe/monolog"
  7. "gitlab.com/beoran/woe/sitef"
  8. )
  9. /* Aptitudes of a being, species or profession */
  10. type Aptitudes struct {
  11. Skills []BeingSkill
  12. Arts []BeingArt
  13. Techniques []BeingTechnique
  14. Exploits []BeingExploit
  15. }
  16. /* Kind of a being or "Kin" for short*/
  17. type Kin struct {
  18. Entity
  19. // Talent modifiers of the species
  20. Talents
  21. // Vitals modifiers of the species
  22. Vitals
  23. Aptitudes
  24. // Arts multiplier in %. If zero arts cannot be used.
  25. Arts float64
  26. // Technique multiplier in %. If zero techniques cannot be used.
  27. Techniques float64
  28. // Learning speed in %
  29. Learning float64
  30. // How much of the being is mechanical.
  31. // Affects healing arts and medication, and the ability to install parts.
  32. Mechanical float64
  33. // Level of Corruption
  34. Corruption float64
  35. // Level of "unliving", i,e, previously alive, matter in the being
  36. Unlife float64
  37. }
  38. func NewKin(id string, name string) *Kin {
  39. res := new(Kin)
  40. res.ID = id
  41. res.Name = name
  42. return res
  43. }
  44. /* Kin modifier display as a string */
  45. func (me Kin) ToKinModifiers() string {
  46. return fmt.Sprintf("ARTS : %4.2f TECHS: %4.2f LEARN: %4.2f\n"+
  47. "MECHA: %4.2f CORRU: %4.2f UNLIF: %4.2f",
  48. me.Arts, me.Techniques, me.Learning, me.Mechanical,
  49. me.Corruption, me.Unlife)
  50. }
  51. /* Help for a kin */
  52. func (me Kin) AskLong() string {
  53. return me.Long + "\n\nTalent modifiers for " + me.Name +
  54. " kin:\n" + me.ToTalents() + "\n\nKin modifiers for " + me.Name +
  55. " kin:\n" + me.ToKinModifiers() + "\n"
  56. }
  57. /* Job of a being */
  58. type Job struct {
  59. Entity
  60. // Talent modifiers of the profession
  61. Talents
  62. // Vitals modifiers of the profession
  63. Vitals
  64. // Map of skills that this job starts with and their levels.
  65. Skills map[string]int
  66. // Same for arts and techniques and exploits
  67. Arts map[string]int
  68. Techniques map[string]int
  69. Exploits map[string]int
  70. // if a player can choose this or not
  71. Playable bool
  72. }
  73. /* Help for a job */
  74. func (me Job) AskLong() string {
  75. return me.Long + "\n\nTalent modifiers for " + me.Name +
  76. " job:\n" + me.ToTalents() + "\n"
  77. }
  78. /* Gender of a being */
  79. type Gender struct {
  80. Entity
  81. // Talent modifiers of the gender
  82. Talents
  83. // Vitals modifiers of the gender
  84. Vitals
  85. }
  86. /* Help for a gender */
  87. func (me Gender) AskLong() string {
  88. return me.Long + "\n\nGender modifiers for " + me.Name +
  89. " gender:\n" + me.ToTalents() + "\n"
  90. }
  91. /* Struct, list and map of all genders in WOE. */
  92. var Genders = struct {
  93. Female Gender
  94. Male Gender
  95. Intersex Gender
  96. Genderless Gender
  97. }{
  98. Gender{
  99. Entity: Entity{ID: "gender_female", Name: "Female",
  100. Short: "Female gender",
  101. Long: "No matter the day and age, there are still plenty of beings who are female. Females are slighly more agile and charismatic than those who have another gender.",
  102. },
  103. Talents: Talents{Agility: 1, Charisma: 1},
  104. },
  105. Gender{
  106. Entity: Entity{ID: "gender_male", Name: "Male",
  107. Short: "Male gender",
  108. Long: "No matter the day and age, there are still plenty of beings who are male. Males are slighly more strong and studious than those who have another gender.",
  109. },
  110. Talents: Talents{Strength: 1, Intelligence: 1},
  111. },
  112. Gender{
  113. Entity: Entity{ID: "gender_intersex", Name: "Intersex",
  114. Short: "Intersexed",
  115. Long: "Not every being can be clearly defined as being male or female. Sometimes, certain beings end up characteristics of both. Intersexed are slighly more dexterous and wise than those who have another gender.",
  116. },
  117. Talents: Talents{Dexterity: 1, Wisdom: 1},
  118. },
  119. Gender{
  120. Entity: Entity{ID: "gender_none", Name: "Genderless",
  121. Short: "No gender",
  122. Long: "Some beings lack reproductive sytems and are therefore genderless. Genderless are slighly more tough and emotionally balanced than those who have another gender.",
  123. },
  124. Talents: Talents{Toughness: 1, Emotion: 1},
  125. },
  126. }
  127. func EntitylikeToGender(me Entitylike) *Gender {
  128. v, ok := me.(*Gender)
  129. if ok {
  130. return v
  131. } else {
  132. return nil
  133. }
  134. }
  135. type EntitylikeSlice []Entitylike
  136. var GenderList = []Gender{Genders.Female, Genders.Male,
  137. Genders.Intersex, Genders.Genderless}
  138. var GenderEntityList = EntitylikeSlice{&Genders.Female, &Genders.Male,
  139. &Genders.Intersex, &Genders.Genderless}
  140. var GenderMap = map[string]*Gender{
  141. Genders.Female.ID: &Genders.Female,
  142. Genders.Male.ID: &Genders.Male,
  143. Genders.Intersex.ID: &Genders.Intersex,
  144. Genders.Genderless.ID: &Genders.Genderless,
  145. }
  146. type EntityIterator interface {
  147. Each(cb func(Entitylike) Entitylike) Entitylike
  148. }
  149. func (me EntitylikeSlice) Each(cb func(Entitylike) Entitylike) Entitylike {
  150. for i := 0; i < len(me); i++ {
  151. res := cb(me[i])
  152. if res != nil {
  153. return res
  154. }
  155. }
  156. return nil
  157. }
  158. func (me EntitylikeSlice) Filter(cb func(Entitylike) Entitylike) EntitylikeSlice {
  159. result := make(EntitylikeSlice, 0)
  160. for i := 0; i < len(me); i++ {
  161. res := cb(me[i])
  162. if res != nil {
  163. result = append(result, res)
  164. }
  165. }
  166. return result
  167. }
  168. /* Finds the name irrespecful of the case */
  169. func (me EntitylikeSlice) FindName(name string) Entitylike {
  170. return me.Each(func(e Entitylike) Entitylike {
  171. if strings.ToLower(e.AsEntity().Name) == strings.ToLower(name) {
  172. return e
  173. } else {
  174. return nil
  175. }
  176. })
  177. }
  178. /* Finds the ID */
  179. func (me EntitylikeSlice) FindID(id string) Entitylike {
  180. if id == "" {
  181. return nil
  182. }
  183. return me.Each(func(e Entitylike) Entitylike {
  184. if strings.ToLower(e.AsEntity().ID) == id {
  185. return e
  186. } else {
  187. return nil
  188. }
  189. })
  190. }
  191. /* Filters the list by privilege level (only those allowed by the level are retained) */
  192. func (me EntitylikeSlice) FilterPrivilege(privilege Privilege) EntitylikeSlice {
  193. return me.Filter(func(e Entitylike) Entitylike {
  194. if e.AsEntity().Privilege <= privilege {
  195. return e
  196. } else {
  197. return nil
  198. }
  199. })
  200. }
  201. /* All Kins of WOE */
  202. var KinList = []Kin{
  203. Kin{
  204. Entity: Entity{
  205. ID: "kin_human", Name: "Human",
  206. Short: "The primordial conscious beings on Earth.",
  207. Long: `Humans are the primordial kind of conscious beings on Earth.
  208. They excel at nothing in particular, but are fast learners.`,
  209. },
  210. // No talents because humans get no talent bonuses
  211. // No stats either because no bonuses there either.
  212. Arts: 1.0,
  213. Techniques: 1.0,
  214. Learning: 1.5,
  215. },
  216. {
  217. Entity: Entity{
  218. ID: "kin_neosa", Name: "Neosa",
  219. Short: "Nimble beings, skilled in the Arts.",
  220. Long: `Neosa are descendents of humans genetically modified to be lite, agile
  221. and skilled with the Numen Arts. They are less tough and strong, and less adept
  222. with techniques. They can be recognized by their long and pointy ears.`,
  223. },
  224. // AGI+1 EMO+1 STR-1 TOU-1
  225. Talents: Talents{Strength: -1, Toughness: -1,
  226. Agility: 1, Emotion: 1},
  227. Arts: 1.2,
  228. Techniques: 0.8,
  229. Learning: 1.0,
  230. },
  231. {
  232. Entity: Entity{
  233. ID: "kin_mantu", Name: "Mantu",
  234. Short: "Hardy, stocky, furry beings, skilled in the Techniques.",
  235. Long: `Mantu are descendents of humans genetically modified to be hardy, stocky
  236. and skilled with Techniques. They are somewhat less agine and less adept with
  237. Numen Arts than humans. They have a soft fur which covers their whole body.`,
  238. },
  239. // STR+1 1 TOU+1 AGI-1 EMO-1
  240. Talents: Talents{Strength: +1, Toughness: +1,
  241. Agility: -1, Emotion: -1},
  242. Arts: 0.8,
  243. Techniques: 1.2,
  244. Learning: 1.0,
  245. },
  246. {
  247. Entity: Entity{
  248. ID: "kin_cyborg", Name: "Cyborg",
  249. Short: "Human enhanced with robotic parts. ",
  250. Long: `Cyborgs are humans who either through neccesity or through their own will,
  251. have been enhanced with robotic parts. They are far more skilled with
  252. Techniques, and can install some Parts, but their Nummen arts are only half
  253. as effective. They are partially mechanical and healing arts and medication
  254. is not as effective on them, but they can be repaired.`,
  255. },
  256. // STR+1 1 TOU+1 DEX+1 INT+1
  257. Talents: Talents{Strength: +1, Toughness: +1,
  258. Dexterity: +1, Intelligence: +1},
  259. Arts: 0.5,
  260. Techniques: 1.5,
  261. Mechanical: 0.5,
  262. Learning: 1.1,
  263. },
  264. {
  265. Entity: Entity{
  266. ID: "kin_android", Name: "Android",
  267. Short: "Human shaped biomchanical robot at the service of humans. ",
  268. Long: `Androids are conscious human shaped robots with the imperative to serve humans.
  269. Highly effective with Techniques, and can install many Parts, but cannot use
  270. any Numen arts. Since thay are not alive, they technically cannot die.`,
  271. },
  272. // STR+1 1 TOU+1 DEX+1 INT+1
  273. Talents: Talents{Strength: +2, Toughness: +2,
  274. Dexterity: +2, Intelligence: +2},
  275. Arts: 0.0,
  276. Techniques: 2.0,
  277. Mechanical: 1.0,
  278. Learning: 1.0,
  279. },
  280. {
  281. Entity: Entity{
  282. ID: "kin_maverick", Name: "Maverick",
  283. Short: "Human shaped biomechanical robot running wild. ",
  284. Long: `Mavericks are androids in which the imperative to serve humans has
  285. been destroyed or disabled. Highly effective with Techniques, and can install
  286. many Parts, but cannot use any Numen arts. Since thay are not alive, they
  287. technically cannot die. They are feared by Humans and hated by Androids.`,
  288. Privilege: PRIVILEGE_IMPLEMENTOR,
  289. },
  290. // STR+1 1 TOU+1 DEX+1 INT+1
  291. Talents: Talents{Strength: +3, Toughness: +3,
  292. Dexterity: +2, Intelligence: +2, Charisma: -2},
  293. Arts: 0.0,
  294. Techniques: 2.0,
  295. Mechanical: 1.0,
  296. Learning: 1.0,
  297. },
  298. {
  299. Entity: Entity{
  300. ID: "kin_robot", Name: "Robot",
  301. Short: "Non conscious mechanical robot.",
  302. Long: `In the wars of the past many robots were built for offense or defense.
  303. Unfortunately, they are self repairing and often even able to replicate
  304. if they find suitable materials. No wonder they are still prowling
  305. the Earth millennia after.`,
  306. Privilege: PRIVILEGE_IMPLEMENTOR,
  307. },
  308. // STR+1 1 TOU+1 DEX+1 INT+1
  309. Talents: Talents{Strength: +4, Toughness: +4,
  310. Dexterity: +2, Intelligence: +2, Charisma: -4},
  311. Arts: 0.0,
  312. Techniques: 2.0,
  313. Mechanical: 1.0,
  314. Learning: 1.0,
  315. },
  316. {
  317. Entity: Entity{
  318. ID: "kin_drone", Name: "Drone",
  319. Short: "Flying combat robot. ",
  320. Long: `Out of control robots are a pain, out of control flying robots even more so!
  321. They might be less though than normal robots, but they move extremely quickly.
  322. `,
  323. Privilege: PRIVILEGE_IMPLEMENTOR,
  324. },
  325. Talents: Talents{Strength: +2, Toughness: +2,
  326. Agility: +4, Dexterity: +2, Intelligence: +2, Charisma: -4},
  327. Arts: 0.0,
  328. Techniques: 2.0,
  329. Mechanical: 1.0,
  330. Learning: 1.0,
  331. },
  332. {
  333. Entity: Entity{
  334. ID: "kin_turret", Name: "Turret",
  335. Short: "Immobile automated defense system. ",
  336. Long: `
  337. The ancients would set up robotic defense system to guard certain areas.
  338. These defense systems might be immobile, but they are deadly accurate.
  339. Furthermore they are extremely resillient and self repairing.
  340. No wonder they are still active after all these years.
  341. `,
  342. Privilege: PRIVILEGE_IMPLEMENTOR,
  343. },
  344. Talents: Talents{Strength: +2, Toughness: +4,
  345. Agility: -4, Dexterity: +4, Intelligence: +4, Charisma: -4},
  346. Arts: 0.0,
  347. Techniques: 2.0,
  348. Mechanical: 1.0,
  349. Learning: 1.0,
  350. },
  351. {
  352. Entity: Entity{
  353. ID: "kin_beast", Name: "Beast",
  354. Short: "Beast that prowls the wild. ",
  355. Long: `Due to the damage to the ecosystem, beasts have rapidly evolved in the last
  356. 60000 years. As a result, most all of them, even the plant eaters, are ferocious
  357. and aggressive, to protect themselves and their offspring from Humans.`,
  358. Privilege: PRIVILEGE_IMPLEMENTOR,
  359. },
  360. Talents: Talents{Strength: +2, Toughness: +2,
  361. Agility: +1, Intelligence: -5},
  362. Arts: 1.0,
  363. Techniques: 1.0,
  364. Learning: 1.0,
  365. },
  366. {
  367. Entity: Entity{
  368. ID: "kin_bird", Name: "Bird",
  369. Short: "Flying being that prowls the wild. ",
  370. Long: `Beasts can be dangerous, flying beasts are all the more so!
  371. They might be less resillient, but all the more agile.`,
  372. Privilege: PRIVILEGE_IMPLEMENTOR,
  373. },
  374. Talents: Talents{Strength: +1, Toughness: +1,
  375. Agility: +3, Intelligence: -5},
  376. Arts: 1.0,
  377. Techniques: 1.0,
  378. Learning: 1.0,
  379. },
  380. {
  381. Entity: Entity{
  382. ID: "kin_fish", Name: "Fish",
  383. Short: "Fish like being that swims the seas or rivers. ",
  384. Long: `Now you know why you were always told not to swim in rivers or seas.
  385. Fish dart through the water, attacking with their razor sharp teeth.
  386. `,
  387. Privilege: PRIVILEGE_IMPLEMENTOR,
  388. },
  389. Talents: Talents{Strength: +3, Toughness: +2,
  390. Agility: +2, Intelligence: -5},
  391. Arts: 1.0,
  392. Techniques: 1.0,
  393. Learning: 1.0,
  394. },
  395. {
  396. Entity: Entity{
  397. ID: "kin_amphibian", Name: "Amphibian",
  398. Short: "Being that lives both on land and in the water. ",
  399. Long: `Covered with a slimy skin and often toxic, these being can not only swim
  400. but also purse you on land.`,
  401. Privilege: PRIVILEGE_IMPLEMENTOR,
  402. },
  403. Talents: Talents{Strength: +1, Toughness: +2,
  404. Agility: +1, Dexterity: +1, Intelligence: -5},
  405. Arts: 1.0,
  406. Techniques: 1.0,
  407. Learning: 1.0,
  408. },
  409. {
  410. Entity: Entity{
  411. ID: "kin_reptile", Name: "Reptile",
  412. Short: "Scaly creepy crawling beasts.",
  413. Long: `Reptiles have been around for a long time, and it looks they will be around for
  414. a long time still. They may be slow, especially in colder weather, nevertheless
  415. they remain dangerous.
  416. `,
  417. Privilege: PRIVILEGE_IMPLEMENTOR,
  418. },
  419. Talents: Talents{Strength: +2, Toughness: +2,
  420. Agility: -1, Intelligence: -5},
  421. Arts: 1.0,
  422. Techniques: 1.0,
  423. Learning: 1.0,
  424. },
  425. {
  426. Entity: Entity{
  427. ID: "kin_crustacean", Name: "Custacian",
  428. Short: "Beast protected by a tough shell",
  429. Long: `You might find it hard to inflict any damage to these well armoured beings.
  430. Their shells protect them against damage and allow them to live in the water
  431. and as well on the land.`,
  432. Privilege: PRIVILEGE_IMPLEMENTOR,
  433. },
  434. Talents: Talents{Strength: +2, Toughness: +4,
  435. Intelligence: -5},
  436. Arts: 1.0,
  437. Techniques: 1.0,
  438. Learning: 1.0,
  439. },
  440. {
  441. Entity: Entity{
  442. ID: "kin_insect", Name: "Insect",
  443. Short: "Beast with articulated legs and bodies.",
  444. Long: `The climate of Earth hs shifted dramaticaly over the last 60000 years,
  445. and as a result, larger creepy crawlers became more successful.
  446. `,
  447. Privilege: PRIVILEGE_IMPLEMENTOR,
  448. },
  449. Talents: Talents{Strength: +2, Toughness: +4, Intelligence: -5},
  450. Arts: 1.0,
  451. Techniques: 1.0,
  452. Learning: 1.0,
  453. },
  454. {
  455. Entity: Entity{
  456. ID: "kin_aquatic", Name: "beast",
  457. Short: "Aquatic beast. ",
  458. Long: `Whether in the rivers or the deep seas, these soft bodies creatures
  459. are often toxic and quite dangerous.`,
  460. Privilege: PRIVILEGE_IMPLEMENTOR,
  461. },
  462. Talents: Talents{Strength: +2, Dexterity: +2, Intelligence: -5},
  463. Arts: 1.0,
  464. Techniques: 1.0,
  465. Learning: 1.0,
  466. },
  467. {
  468. Entity: Entity{
  469. ID: "kin_corrupted", Name: "corrupted",
  470. Short: "Beast corupted by Omen. ",
  471. Long: `Some animals became corrupted by Omen. As a result, they became much stronger
  472. and more resillient. Fortunately, the Omen is weak against certain Numen arts.
  473. Beware, their attacks might be contageous...`,
  474. Privilege: PRIVILEGE_IMPLEMENTOR,
  475. },
  476. Talents: Talents{Strength: +4, Toughness: +4,
  477. Agility: +1, Intelligence: -3, Wisdom: -5},
  478. Arts: 1.0,
  479. Techniques: 1.0,
  480. Corruption: 1.0,
  481. Learning: 1.0,
  482. },
  483. {
  484. Entity: Entity{
  485. ID: "kin_deceased", Name: "Deceased",
  486. Short: "Deceased biological being animated by Omen. ",
  487. Long: `Some living beings become corrupted by Omen to the point that they remain
  488. animated even after their biological bodies have already stopped functioning.
  489. Such beings are termed the Deceased. They are resillient, strong and cunning.
  490. Fortunately, the Omen is weak against certain Numen arts. But beware, their
  491. attacks might be contageous...
  492. `,
  493. Privilege: PRIVILEGE_IMPLEMENTOR,
  494. },
  495. Talents: Talents{Strength: +2, Toughness: +2,
  496. Agility: +1, Intelligence: -1, Wisdom: -7},
  497. Arts: 1.0,
  498. Techniques: 1.0,
  499. Learning: 1.0,
  500. Corruption: 1.0,
  501. Unlife: 1.0,
  502. },
  503. }
  504. var KinEntityList EntitylikeSlice
  505. func init() {
  506. KinEntityList = make(EntitylikeSlice, len(KinList))
  507. for i := range KinList {
  508. e := KinList[i]
  509. monolog.Debug("KinList: %s", e.Name)
  510. KinEntityList[i] = &e
  511. }
  512. }
  513. func EntitylikeToKin(me Entitylike) *Kin {
  514. v, ok := me.(*Kin)
  515. if ok {
  516. return v
  517. } else {
  518. return nil
  519. }
  520. }
  521. /* All jobs of WOE
  522. * agent officer guardian
  523. * worker brawler builder
  524. * hunter gunsman rogue
  525. * explorer ranger rebel
  526. * tinker engineer wrecker
  527. * homemaker musician trader
  528. * scholar scientist hacker
  529. * medic cleric artist
  530. * esper dilettante (not playable) Danger
  531. *
  532. *
  533. * hunter scholar esper worker medic agent officer cleric guardian ranger
  534. * wrecker engineer tinker scientist
  535. *
  536. *
  537. *
  538. Agent STR + 2
  539. Worker TOU + 2
  540. Engineer DEX + 2
  541. Hunter AGI + 2
  542. Scholar INT + 2
  543. Medic WIS + 2
  544. Cleric CHA + 2
  545. *
  546. *
  547. */
  548. var JobList = []Job{
  549. {Entity: Entity{
  550. ID: "job_agent", Name: "Agent",
  551. Short: "Agent employed by the government of Eruta.",
  552. Long: `Agents work for the government of Eruta. They are given all sorts of tasks, but tend to focus on capturing criminals. Physical strength is their forte.
  553. `,
  554. },
  555. Talents: Talents{Strength: +2},
  556. Skills: map[string]int{
  557. "skill_sword": 10,
  558. "skill_heavy_gear": 10,
  559. "skill_acrobatics": 5,
  560. "skill_cannon": 5,
  561. "skill_weaponsmith": 5,
  562. },
  563. Playable: true,
  564. },
  565. {Entity: Entity{
  566. ID: "job_worker", Name: "Worker",
  567. Short: "Worker in construction or mining.",
  568. Long: `Workers take on the more heavy jobs such as construction and mining. They are a tough lot.
  569. `,
  570. },
  571. Talents: Talents{Toughness: +2},
  572. Skills: map[string]int{
  573. "skill_maul": 10,
  574. "skill_heavy_gear": 10,
  575. "skill_toiling": 5,
  576. "skill_explosives": 5,
  577. "skill_mining": 5,
  578. },
  579. Playable: true,
  580. },
  581. {Entity: Entity{
  582. ID: "job_engineer", Name: "Engineer",
  583. Short: "Expert in machines and technology.",
  584. Long: `Engineers are experts in technology. They can construct and repair most any machine. They tend to be higly dexterous.
  585. `,
  586. },
  587. Talents: Talents{Toughness: +2},
  588. Skills: map[string]int{
  589. "skill_gun": 10,
  590. "skill_medium_gear": 10,
  591. "skill_engineering": 5,
  592. "skill_fist": 5,
  593. "skill_gunsmith": 5,
  594. },
  595. Playable: true,
  596. },
  597. {Entity: Entity{
  598. ID: "job_hunter", Name: "Hunter",
  599. Short: "Hunter who chases beasts and mavericks.",
  600. Long: `Hunters protect human settlements from Beasts and Mavericks, and try to keep their numbers down. They excel in Agility.
  601. `,
  602. },
  603. Talents: Talents{Agility: +2},
  604. Skills: map[string]int{
  605. "skill_polearm": 10,
  606. "skill_medium_gear": 10,
  607. "skill_shield": 5,
  608. "skill_gun": 5,
  609. "skill_survival": 5,
  610. },
  611. Playable: true,
  612. },
  613. {Entity: Entity{
  614. ID: "job_scholar", Name: "Scholar",
  615. Short: "Scholar who studies science.",
  616. Long: `Scolars focus in studying science and discovering what was previously unknown. Reknowned for their intelligence.
  617. `,
  618. },
  619. Talents: Talents{Intelligence: +2},
  620. Skills: map[string]int{
  621. "skill_staff": 10,
  622. "skill_light_gear": 10,
  623. "skill_science": 5,
  624. "skill_lore": 5,
  625. "skill_artistic": 5,
  626. },
  627. Playable: true,
  628. },
  629. {Entity: Entity{
  630. ID: "job_medic", Name: "Medic",
  631. Short: "Medic who heals the wounded and cures the ill.",
  632. Long: `Medics focus on healing the wounded and curng the ill. Need wisdom to deal with their patients.
  633. `,
  634. },
  635. Talents: Talents{Wisdom: +2},
  636. Skills: map[string]int{
  637. "skill_knife": 10,
  638. "skill_light_gear": 10,
  639. "skill_medical": 5,
  640. "skill_bravery": 5,
  641. "skill_gun": 5,
  642. },
  643. Playable: true,
  644. },
  645. {Entity: Entity{
  646. ID: "job_cleric", Name: "Cleric",
  647. Short: "Clerics tend to the spiritual.",
  648. Long: `Clerics tend to the spiritual well being of others in the name of Lord Kei. It is a job that requires high Charisma.`,
  649. },
  650. Talents: Talents{Charisma: +2},
  651. Skills: map[string]int{
  652. "skill_fist": 10,
  653. "skill_light_gear": 10,
  654. "skill_shield": 5,
  655. "skill_social": 5,
  656. "skill_arcane": 5,
  657. },
  658. Playable: true,
  659. },
  660. }
  661. var JobEntityList EntitylikeSlice
  662. func init() {
  663. JobEntityList = make(EntitylikeSlice, len(JobList))
  664. for i := range JobList {
  665. e := JobList[i]
  666. monolog.Debug("JobList: %s", e.Name)
  667. JobEntityList[i] = &e
  668. }
  669. }
  670. func EntitylikeToJob(me Entitylike) *Job {
  671. v, ok := me.(*Job)
  672. if ok {
  673. return v
  674. } else {
  675. return nil
  676. }
  677. }
  678. type LabeledPointer struct {
  679. ID string
  680. labeled *Labeled
  681. }
  682. type GenderPointer struct {
  683. ID string
  684. gender *Gender
  685. }
  686. //}
  687. /* Vital statistic of a Being. */
  688. type Vital struct {
  689. Now int `xml:"N,attr"`
  690. Max int `xml:"X,attr"`
  691. }
  692. /* Report a vital statistic as a Now/Max string */
  693. func (me *Vital) ToNowMax() string {
  694. return fmt.Sprintf("%4d/%4d", me.Now, me.Max)
  695. }
  696. // alias of the above, since I'm lazy at times
  697. func (me *Vital) TNM() string {
  698. return me.ToNowMax()
  699. }
  700. /* Report a vital statistic as a rounded percentage */
  701. func (me *Vital) ToPercentage() string {
  702. percentage := (me.Now * 100) / me.Max
  703. return fmt.Sprintf("%d", percentage)
  704. }
  705. /* Report a vital statistic as a bar of characters */
  706. func (me *Vital) ToBar(full string, empty string, length int) string {
  707. numfull := (me.Now * length) / me.Max
  708. numempty := length - numfull
  709. return strings.Repeat(empty, numempty) + strings.Repeat(full, numfull)
  710. }
  711. type Talents struct {
  712. Strength int `xml:"Talents>STR,omitempty"`
  713. Toughness int `xml:"Talents>TOU,omitempty"`
  714. Agility int `xml:"Talents>AGI,omitempty"`
  715. Dexterity int `xml:"Talents>DEX,omitempty"`
  716. Intelligence int `xml:"Talents>INT,omitempty"`
  717. Wisdom int `xml:"Talents>WIS,omitempty"`
  718. Charisma int `xml:"Talents>CHA,omitempty"`
  719. Emotion int `xml:"Talents>EMO,omitempty"`
  720. }
  721. type Vitals struct {
  722. HP Vital
  723. MP Vital
  724. JP Vital
  725. LP Vital
  726. }
  727. type EquipmentValues struct {
  728. Offense int
  729. Protection int
  730. Block int
  731. Rapidity int
  732. Yield int
  733. }
  734. type Being struct {
  735. Entity
  736. // Essentials
  737. *Gender
  738. *Kin
  739. *Job
  740. Level int
  741. // A being has talents.
  742. Talents
  743. // A being has vitals
  744. Vitals
  745. // A being has Equipment values
  746. EquipmentValues
  747. // A being has aptitudes
  748. Aptitudes
  749. // Skills map[string]BeingSkill
  750. // Arts array
  751. // Arts []Art
  752. // Affects array
  753. // Affects []Affect
  754. // Equipment
  755. Equipment
  756. // Inventory
  757. Inventory
  758. // Location pointer
  759. Room *Room
  760. }
  761. var BasicTalent Talents = Talents{
  762. Strength: 10,
  763. Toughness: 10,
  764. Agility: 10,
  765. Dexterity: 10,
  766. Intelligence: 10,
  767. Wisdom: 10,
  768. Charisma: 10,
  769. Emotion: 10,
  770. }
  771. // Derived stats
  772. func (me *Talents) Force() int {
  773. return (me.Strength*2 + me.Wisdom) / 3
  774. }
  775. func (me *Talents) Vitality() int {
  776. return (me.Toughness*2 + me.Charisma) / 3
  777. }
  778. func (me *Talents) Quickness() int {
  779. return (me.Agility*2 + me.Intelligence) / 3
  780. }
  781. func (me *Talents) Knack() int {
  782. return (me.Dexterity*2 + me.Emotion) / 3
  783. }
  784. func (me *Talents) Understanding() int {
  785. return (me.Intelligence*2 + me.Toughness) / 3
  786. }
  787. func (me *Talents) Grace() int {
  788. return (me.Charisma*2 + me.Agility) / 3
  789. }
  790. func (me *Talents) Zeal() int {
  791. return (me.Wisdom*2 + me.Strength) / 3
  792. }
  793. func (me *Talents) Numen() int {
  794. return (me.Emotion*2 + me.Dexterity) / 3
  795. }
  796. /*
  797. Stats of beings:
  798. Talents:
  799. *
  800. * Talents describe the basic constitution of a being.
  801. Strength: explosive physical strength
  802. Toughness: physical resillience
  803. Agility: Speed of motion and bodily balance
  804. Dexterity: Fine motor sills and hand eye coordination
  805. Intelligence: Book smarts and studiousness
  806. Wisdom: Insight and intution
  807. Emotion: Emotional control and insight.
  808. Charisma: Social abilities and appeal to others
  809. Force: Physical and mental vigor.
  810. Vitality: Resistance against damage.
  811. Quickness: Phyisical and mental speed.
  812. Knack: Manual and mental adroitness
  813. Understanding: Deep insight though stubborn work.
  814. Grace: Appeal and delicacy of motion and presence.
  815. Zeal: Mental and religious perspicacity.
  816. Numen: Effectiveness of arts through passion and quick hands.
  817. HP: Hull Power/ Health Power: Protection against wounds. When 0, the being is
  818. likely to get stunned and vulnerable against LP damage.
  819. MP: Motion Power. Needed for motion and performing techniques.
  820. JP: Junction Power. Needed for Numen arts.
  821. LP: Life Power. Resilience to actual wounds. When 0, the being dies or is
  822. destroyed.
  823. Offense: Effectiveness of weapon (ranged or melee).
  824. Protection: Effectiveness of armor.
  825. Blocking: Efectiveness of shield or parrying weapon.
  826. Rapidity: Gain or loss of speed due to armor (may be negative).
  827. Calculations:
  828. Life Power LP Vitality / 2 + KIN_LP_BONUS
  829. Husk Power HP (((Level * Vitality) div 5) + Level*2 + Vitality*2 + 8) * RACE_HP_MUL
  830. Junction Power JP ((Level * Numen) div 4) + Level*2 + Numen*2) * RACE_JP_MUL
  831. Motion Power MP (((Level * Zeal) div 4) + Level * 2 + Zeal * 2) + 30) * RACE_MP_MUL
  832. XXX: this will be changd to only include Equipment related values, skill and talent are added to the calculation later.
  833. Offense OFF Quality of equipped weapon
  834. Protection PRO Sum of quality of equipped gear.
  835. Blocking BLO (shield quality ) OR ( weapon skill + weapon quality ) if learned weapon's parry technique, otherwise ineffective.
  836. Rapidity RAP - weight of armor - weight of shield - weight of weapon.
  837. Yield YIE Numen - interference penalty of gear - interference penalty of shield - interference of weapon + quality of staff if equipped + quality of equipped Focus.
  838. Offense
  839. Protection
  840. Block
  841. Rapidity
  842. Yield
  843. */
  844. // Generates a prompt for use with the being/character
  845. func (me *Being) ToPrompt() string {
  846. if (me.Kin != nil) && (me.Kin.Arts > 0.0) {
  847. return fmt.Sprintf("HP:%s MP:%s LP:%s JP:%s", me.HP.TNM(), me.MP.TNM(), me.LP.TNM(), me.JP.TNM())
  848. } else {
  849. return fmt.Sprintf("HP:%s MP:%s LP:%s", me.HP.TNM(), me.MP.TNM(), me.LP.TNM())
  850. }
  851. }
  852. func (me *Being) GenderName() string {
  853. if me.Gender == nil {
  854. return "????"
  855. }
  856. return me.Gender.Name
  857. }
  858. func (me *Being) KinName() string {
  859. if me.Kin == nil {
  860. return "????"
  861. }
  862. return me.Kin.Name
  863. }
  864. func (me *Being) JobName() string {
  865. if me.Job == nil {
  866. return "????"
  867. }
  868. return me.Job.Name
  869. }
  870. // Generates an overview of the essentials of the being as a string.
  871. func (me *Being) ToEssentials() string {
  872. return fmt.Sprintf("%s lvl %d %s %s %s", me.Name, me.Level, me.GenderName(), me.KinName(), me.JobName())
  873. }
  874. // Generates an overview of the physical talents of the being as a string.
  875. func (me *Talents) ToBodyTalents() string {
  876. return fmt.Sprintf("STR: %3d TOU: %3d AGI: %3d DEX: %3d", me.Strength, me.Toughness, me.Agility, me.Dexterity)
  877. }
  878. // Generates an overview of the mental talents of the being as a string.
  879. func (me *Talents) ToMindTalents() string {
  880. return fmt.Sprintf("INT: %3d WIS: %3d CHA: %3d EMO: %3d", me.Intelligence, me.Wisdom, me.Charisma, me.Emotion)
  881. }
  882. // Generates an overview of the physical derived talents of the being as a string.
  883. func (me *Talents) ToBodyDerived() string {
  884. return fmt.Sprintf("FOR: %3d VIT: %3d QUI: %3d KNA: %3d", me.Force(), me.Vitality(), me.Quickness(), me.Knack())
  885. }
  886. // Generates an overview of the mental derived talents of the being as a string.
  887. func (me *Talents) ToMindDerived() string {
  888. return fmt.Sprintf("UND: %3d GRA: %3d ZEA: %3d NUM: %3d", me.Understanding(), me.Grace(), me.Zeal(), me.Numen())
  889. }
  890. // Generates an overview of the derived talents of the being as a string.
  891. func (me *Talents) ToDerived() string {
  892. status := me.ToBodyDerived()
  893. status += "\n" + me.ToMindDerived()
  894. return status
  895. }
  896. // Generates an overview of all talents as a string.
  897. func (me *Talents) ToTalents() string {
  898. status := me.ToBodyTalents()
  899. status += "\n" + me.ToMindTalents()
  900. return status
  901. }
  902. // Generates an overview of the equipment values of the being as a string.
  903. func (me *EquipmentValues) ToEquipmentValues() string {
  904. return fmt.Sprintf("OFF: %3d PRO: %3d BLO: %3d RAP: %3d YIE: %3d", me.Offense, me.Protection, me.Block, me.Rapidity, me.Yield)
  905. }
  906. // Generates an overview of the status of the being as a string.
  907. func (me *Being) ToStatus() string {
  908. status := me.ToEssentials()
  909. status += "\n" + me.ToTalents()
  910. status += "\n" + me.ToDerived()
  911. status += "\n" + me.ToEquipmentValues()
  912. status += "\n" + me.ToPrompt()
  913. status += "\n"
  914. return status
  915. }
  916. func (me *Talents) GrowFrom(from Talents) {
  917. me.Strength += from.Strength
  918. me.Toughness += from.Toughness
  919. me.Agility += from.Agility
  920. me.Dexterity += from.Dexterity
  921. me.Intelligence += from.Intelligence
  922. me.Wisdom += from.Wisdom
  923. me.Charisma += from.Charisma
  924. me.Emotion += from.Emotion
  925. }
  926. func (me *Vital) NewMax(max int) {
  927. oldmax := me.Max
  928. me.Max = max
  929. delta := me.Max - oldmax
  930. me.Now += delta
  931. if me.Now > me.Max {
  932. me.Now = me.Max
  933. }
  934. if me.Now < 0 {
  935. me.Now = 0
  936. }
  937. }
  938. func (me *Being) RecalculateVitals() {
  939. newhp := (me.Level * me.Vitality() / 5) + me.Level*2 + me.Vitality()*2
  940. newhp += 8
  941. me.Vitals.HP.NewMax(newhp)
  942. me.Vitals.LP.NewMax((me.Vitality()/2 + 4))
  943. newjp := (me.Level*me.Numen())/4 + me.Level*2 + me.Numen()*2
  944. newjpf := float64(newjp)
  945. newmp := (me.Level*me.Zeal())/4 + me.Level*2 + me.Zeal()*2 + 32
  946. newmpf := float64(newmp)
  947. if me.Kin != nil {
  948. newjpf *= me.Kin.Arts
  949. newmpf *= me.Kin.Techniques
  950. }
  951. me.Vitals.MP.NewMax(int(math.Floor(newjpf)))
  952. me.Vitals.JP.NewMax(int(math.Floor(newmpf)))
  953. }
  954. func (me *Being) Init(kind string, name string, privilege Privilege,
  955. kin Entitylike, gender Entitylike, job Entitylike) *Being {
  956. if me == nil {
  957. return me
  958. }
  959. me.Entity.InitKind(kind, name, privilege)
  960. realkin := EntitylikeToKin(kin)
  961. realgen := EntitylikeToGender(gender)
  962. realjob := EntitylikeToJob(job)
  963. monolog.Info("Init being: Kin: %v", realkin)
  964. monolog.Info("Init being: Gender: %v", realgen)
  965. monolog.Info("Init being: Job: %v", realjob)
  966. me.Kin = realkin
  967. me.Gender = realgen
  968. me.Job = realjob
  969. me.Talents.GrowFrom(BasicTalent)
  970. me.Talents.GrowFrom(me.Kin.Talents)
  971. me.Talents.GrowFrom(me.Gender.Talents)
  972. me.Talents.GrowFrom(me.Job.Talents)
  973. me.Level = 1
  974. me.RecalculateVitals()
  975. return me
  976. }
  977. func NewBeing(kind string, name string, privilege Privilege,
  978. kin Entitylike, gender Entitylike, job Entitylike) *Being {
  979. res := &Being{}
  980. res.Init(kind, name, privilege, kin, gender, job)
  981. return res
  982. }
  983. func (me *Being) Type() string {
  984. return "being"
  985. }
  986. func (me *Being) Save(datadir string) {
  987. SaveSavable(datadir, me)
  988. }
  989. func LoadBeing(datadir string, nameid string) *Being {
  990. res, _ := LoadLoadable(datadir, nameid, new(Being)).(*Being)
  991. return res
  992. }
  993. func (me *Talents) SaveSitef(rec *sitef.Record) (err error) {
  994. rec.PutStruct("", *me)
  995. return nil
  996. }
  997. func (me *Vitals) SaveSitef(rec *sitef.Record) (err error) {
  998. rec.PutStruct("", *me)
  999. return nil
  1000. }
  1001. func (me *EquipmentValues) SaveSitef(rec *sitef.Record) (err error) {
  1002. rec.PutStruct("", *me)
  1003. return nil
  1004. }
  1005. func (me *Aptitudes) SaveSitef(rec *sitef.Record) (err error) {
  1006. nskills := len(me.Skills)
  1007. rec.PutInt("skills", nskills)
  1008. for i := 0; i < nskills; i++ {
  1009. rec.PutArrayIndex("skills", i, me.Skills[i].skill.ID)
  1010. }
  1011. return nil
  1012. }
  1013. func (me *Inventory) SaveSitef(rec *sitef.Record) (err error) {
  1014. return nil
  1015. }
  1016. // Save a being to a sitef record.
  1017. func (me *Being) SaveSitef(rec *sitef.Record) (err error) {
  1018. me.Entity.SaveSitef(rec)
  1019. rec.PutInt("level", me.Level)
  1020. if me.Gender != nil {
  1021. rec.Put("gender", me.Gender.ID)
  1022. }
  1023. if me.Job != nil {
  1024. rec.Put("job", me.Job.ID)
  1025. }
  1026. if me.Kin != nil {
  1027. rec.Put("kin", me.Kin.ID)
  1028. }
  1029. me.Talents.SaveSitef(rec)
  1030. me.Vitals.SaveSitef(rec)
  1031. me.EquipmentValues.SaveSitef(rec)
  1032. me.Aptitudes.SaveSitef(rec)
  1033. me.Inventory.SaveSitef(rec)
  1034. if me.Room != nil {
  1035. rec.Put("room", me.Room.ID)
  1036. }
  1037. return nil
  1038. }
  1039. func (me *Talents) LoadSitef(rec sitef.Record) (err error) {
  1040. rec.GetStruct("", me)
  1041. return nil
  1042. }
  1043. func (me *Vitals) LoadSitef(rec sitef.Record) (err error) {
  1044. rec.GetStruct("", me)
  1045. return nil
  1046. }
  1047. func (me *EquipmentValues) LoadSitef(rec sitef.Record) (err error) {
  1048. rec.GetStruct("", me)
  1049. return nil
  1050. }
  1051. func (me *Aptitudes) LoadSitef(rec sitef.Record) (err error) {
  1052. // rec.GetStruct("", *me)
  1053. return nil
  1054. }
  1055. func (me *Inventory) LoadSitef(rec sitef.Record) (err error) {
  1056. // rec.GetStruct("", *me)
  1057. return nil
  1058. }
  1059. // Load a being from a sitef record.
  1060. func (me *Being) LoadSitef(rec sitef.Record) (err error) {
  1061. me.Entity.LoadSitef(rec)
  1062. me.Level = rec.GetIntDefault("level", 1)
  1063. me.Gender = EntitylikeToGender(GenderEntityList.FindID(rec.Get("gender")))
  1064. me.Job = EntitylikeToJob(JobEntityList.FindID(rec.Get("job")))
  1065. me.Kin = EntitylikeToKin(KinEntityList.FindID(rec.Get("kin")))
  1066. me.Talents.LoadSitef(rec)
  1067. me.Vitals.LoadSitef(rec)
  1068. me.EquipmentValues.LoadSitef(rec)
  1069. me.Aptitudes.LoadSitef(rec)
  1070. me.Inventory.LoadSitef(rec)
  1071. if rec.Get("room") != "" {
  1072. var err error
  1073. me.Room, err = DefaultWorld.LoadRoom(rec.Get("room"))
  1074. if err != nil {
  1075. monolog.WriteError(err)
  1076. return err
  1077. }
  1078. }
  1079. return nil
  1080. }