You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

950 lines
28 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
2 years ago
1 year ago
1 year ago
1 year ago
4 years ago
2 years ago
1 year ago
1 year ago
1 year ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
  1. #![allow(dead_code)]
  2. use std::collections::HashMap;
  3. use std::convert::Into;
  4. use serde::{Serialize, Deserialize};
  5. use libpso::character::settings;
  6. use libpso::util::vec_to_array;
  7. use crate::entity::account::*;
  8. use crate::entity::character::*;
  9. use crate::entity::item::*;
  10. use crate::entity::room::*;
  11. use crate::ship::map::MapArea;
  12. use crate::ship::room::{Episode, Difficulty};
  13. use crate::ship::monster::MonsterType;
  14. #[derive(Debug, sqlx::FromRow)]
  15. pub struct PgUserAccount {
  16. id: i32,
  17. username: String,
  18. password: String,
  19. banned: Option<chrono::DateTime<chrono::Utc>>,
  20. muted: Option<chrono::DateTime<chrono::Utc>>,
  21. created_at: chrono::DateTime<chrono::Utc>,
  22. flags: i32,
  23. activated: bool,
  24. at_login: bool,
  25. at_character: bool,
  26. at_ship: bool,
  27. }
  28. impl From<PgUserAccount> for UserAccountEntity {
  29. fn from(other: PgUserAccount) -> UserAccountEntity {
  30. UserAccountEntity {
  31. id: UserAccountId(other.id as u32),
  32. username: other.username,
  33. password: other.password,
  34. banned_until: other.banned,
  35. muted_until: other.muted,
  36. created_at: other.created_at,
  37. flags: other.flags as u32,
  38. guildcard: other.id as u32 + 1,
  39. team_id: None,
  40. activated: other.activated,
  41. at_login: other.at_login,
  42. at_character: other.at_character,
  43. at_ship: other.at_ship,
  44. }
  45. }
  46. }
  47. #[derive(Debug, sqlx::FromRow)]
  48. pub struct PgUserSettings {
  49. id: i32,
  50. user_account: i32,
  51. blocked_users: Vec<u8>, //[u32; 0x1E],
  52. key_config: Vec<u8>, //[u8; 0x16C],
  53. joystick_config: Vec<u8>, //[u8; 0x38],
  54. option_flags: i32,
  55. shortcuts: Vec<u8>, //[u8; 0xA40],
  56. symbol_chats: Vec<u8>, //[u8; 0x4E0],
  57. team_name: Vec<u8>, //[u16; 0x10],
  58. }
  59. impl From<PgUserSettings> for UserSettingsEntity {
  60. fn from(other: PgUserSettings) -> UserSettingsEntity {
  61. UserSettingsEntity {
  62. id: UserSettingsId(other.id as u32),
  63. user_id: UserAccountId(other.user_account as u32),
  64. settings: settings::UserSettings {
  65. blocked_users: vec_to_array(other.blocked_users.chunks(4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()),
  66. keyboard_config: vec_to_array(other.key_config),
  67. gamepad_config: vec_to_array(other.joystick_config),
  68. option_flags: other.option_flags as u32,
  69. shortcuts: vec_to_array(other.shortcuts),
  70. symbol_chats: vec_to_array(other.symbol_chats),
  71. team_name: vec_to_array(other.team_name.chunks(2).map(|b| u16::from_le_bytes([b[0], b[1]])).collect()),
  72. }
  73. }
  74. }
  75. }
  76. #[derive(sqlx::Type, Debug)]
  77. #[sqlx(rename_all = "lowercase")]
  78. pub enum PgCharacterClass {
  79. HUmar,
  80. HUnewearl,
  81. HUcast,
  82. HUcaseal,
  83. RAmar,
  84. RAmarl,
  85. RAcast,
  86. RAcaseal,
  87. FOmar,
  88. FOmarl,
  89. FOnewm,
  90. FOnewearl,
  91. }
  92. impl From<PgCharacterClass> for CharacterClass {
  93. fn from(other: PgCharacterClass) -> CharacterClass {
  94. match other{
  95. PgCharacterClass::HUmar => CharacterClass::HUmar,
  96. PgCharacterClass::HUnewearl => CharacterClass::HUnewearl,
  97. PgCharacterClass::HUcast => CharacterClass::HUcast,
  98. PgCharacterClass::HUcaseal => CharacterClass::HUcaseal,
  99. PgCharacterClass::RAmar => CharacterClass::RAmar,
  100. PgCharacterClass::RAmarl => CharacterClass::RAmarl,
  101. PgCharacterClass::RAcast => CharacterClass::RAcast,
  102. PgCharacterClass::RAcaseal => CharacterClass::RAcaseal,
  103. PgCharacterClass::FOmar => CharacterClass::FOmar,
  104. PgCharacterClass::FOmarl => CharacterClass::FOmarl,
  105. PgCharacterClass::FOnewm => CharacterClass::FOnewm,
  106. PgCharacterClass::FOnewearl => CharacterClass::FOnewearl,
  107. }
  108. }
  109. }
  110. impl From<CharacterClass> for PgCharacterClass {
  111. fn from(other: CharacterClass) -> PgCharacterClass {
  112. match other {
  113. CharacterClass::HUmar => PgCharacterClass::HUmar,
  114. CharacterClass::HUnewearl => PgCharacterClass::HUnewearl,
  115. CharacterClass::HUcast => PgCharacterClass::HUcast,
  116. CharacterClass::HUcaseal => PgCharacterClass::HUcaseal,
  117. CharacterClass::RAmar => PgCharacterClass::RAmar,
  118. CharacterClass::RAmarl => PgCharacterClass::RAmarl,
  119. CharacterClass::RAcast => PgCharacterClass::RAcast,
  120. CharacterClass::RAcaseal => PgCharacterClass::RAcaseal,
  121. CharacterClass::FOmar => PgCharacterClass::FOmar,
  122. CharacterClass::FOmarl => PgCharacterClass::FOmarl,
  123. CharacterClass::FOnewm => PgCharacterClass::FOnewm,
  124. CharacterClass::FOnewearl => PgCharacterClass::FOnewearl,
  125. }
  126. }
  127. }
  128. #[derive(sqlx::Type, Debug)]
  129. #[sqlx(rename_all = "lowercase")]
  130. pub enum PgSectionId {
  131. Viridia,
  132. Greenill,
  133. Skyly,
  134. Bluefull,
  135. Purplenum,
  136. Pinkal,
  137. Redria,
  138. Oran,
  139. Yellowboze,
  140. Whitill,
  141. }
  142. impl From<PgSectionId> for SectionID {
  143. fn from(other: PgSectionId) -> SectionID {
  144. match other {
  145. PgSectionId::Viridia => SectionID::Viridia,
  146. PgSectionId::Greenill => SectionID::Greenill,
  147. PgSectionId::Skyly => SectionID::Skyly,
  148. PgSectionId::Bluefull => SectionID::Bluefull,
  149. PgSectionId::Purplenum => SectionID::Purplenum,
  150. PgSectionId::Pinkal => SectionID::Pinkal,
  151. PgSectionId::Redria => SectionID::Redria,
  152. PgSectionId::Oran => SectionID::Oran,
  153. PgSectionId::Yellowboze => SectionID::Yellowboze,
  154. PgSectionId::Whitill => SectionID::Whitill,
  155. }
  156. }
  157. }
  158. impl From<SectionID> for PgSectionId {
  159. fn from(other: SectionID) -> PgSectionId {
  160. match other {
  161. SectionID::Viridia => PgSectionId::Viridia,
  162. SectionID::Greenill => PgSectionId::Greenill,
  163. SectionID::Skyly => PgSectionId::Skyly,
  164. SectionID::Bluefull => PgSectionId::Bluefull,
  165. SectionID::Purplenum => PgSectionId::Purplenum,
  166. SectionID::Pinkal => PgSectionId::Pinkal,
  167. SectionID::Redria => PgSectionId::Redria,
  168. SectionID::Oran => PgSectionId::Oran,
  169. SectionID::Yellowboze => PgSectionId::Yellowboze,
  170. SectionID::Whitill => PgSectionId::Whitill,
  171. }
  172. }
  173. }
  174. #[derive(Debug, sqlx::FromRow)]
  175. pub struct PgCharacter {
  176. pub id: i32,
  177. user_account: i32,
  178. pub slot: i16,
  179. name: String,
  180. exp: i32,
  181. class: String,
  182. section_id: String,
  183. costume: i16,
  184. skin: i16,
  185. face: i16,
  186. head: i16,
  187. hair: i16,
  188. hair_r: i16,
  189. hair_g: i16,
  190. hair_b: i16,
  191. prop_x: f32,
  192. prop_y: f32,
  193. techs: Vec<u8>,
  194. config: Vec<u8>,
  195. infoboard: String,
  196. guildcard: String,
  197. option_flags: i32,
  198. power: i16,
  199. mind: i16,
  200. def: i16,
  201. evade: i16,
  202. luck: i16,
  203. hp: i16,
  204. tp: i16,
  205. tech_menu: Vec<u8>,
  206. playtime: i32,
  207. }
  208. impl From<PgCharacter> for CharacterEntity {
  209. fn from(other: PgCharacter) -> CharacterEntity {
  210. CharacterEntity {
  211. id: CharacterEntityId(other.id as u32),
  212. user_id: UserAccountId(other.user_account as u32),
  213. slot: other.slot as u32,
  214. name: other.name,
  215. exp: other.exp as u32,
  216. char_class: other.class.parse().unwrap(),
  217. section_id: other.section_id.parse().unwrap(),
  218. appearance: CharacterAppearance {
  219. costume: other.costume as u16,
  220. skin: other.skin as u16,
  221. face: other.face as u16,
  222. head: other.head as u16,
  223. hair: other.hair as u16,
  224. hair_r: other.hair_r as u16,
  225. hair_g: other.hair_g as u16,
  226. hair_b: other.hair_b as u16,
  227. prop_x: other.prop_x,
  228. prop_y: other.prop_y,
  229. },
  230. techs: CharacterTechniques {
  231. techs: other.techs.iter().enumerate().take(19).filter(|(_, t)| **t != 0xFF).map(|(i, t)| (tech::Technique::from_value(i as u8), TechLevel(*t + 1)) ).collect()
  232. },
  233. config: CharacterConfig {
  234. raw_data: vec_to_array(other.config)
  235. },
  236. info_board: CharacterInfoboard {
  237. board: libpso::utf8_to_utf16_array!(other.infoboard, 172),
  238. },
  239. guildcard: CharacterGuildCard {
  240. description: other.guildcard,
  241. },
  242. option_flags: other.option_flags as u32,
  243. materials: CharacterMaterials {
  244. power: other.power as u32,
  245. mind: other.mind as u32,
  246. def: other.def as u32,
  247. evade: other.evade as u32,
  248. luck: other.luck as u32,
  249. hp: other.hp as u32,
  250. tp: other.tp as u32,
  251. },
  252. tech_menu: CharacterTechMenu {
  253. tech_menu: vec_to_array(other.tech_menu)
  254. },
  255. playtime: other.playtime as u32,
  256. }
  257. }
  258. }
  259. #[derive(Debug, sqlx::FromRow)]
  260. pub struct PgGuildCard {
  261. }
  262. #[derive(Debug, Serialize, Deserialize)]
  263. pub struct PgWeapon {
  264. weapon: weapon::WeaponType,
  265. special: Option<weapon::WeaponSpecial>,
  266. grind: u8,
  267. attrs: HashMap<weapon::Attribute, i8>,
  268. tekked: bool,
  269. }
  270. impl From<weapon::Weapon> for PgWeapon {
  271. fn from(other: weapon::Weapon) -> PgWeapon {
  272. PgWeapon {
  273. weapon: other.weapon,
  274. special: other.special,
  275. grind: other.grind,
  276. attrs: other.attrs.iter().flatten().map(|attr| (attr.attr, attr.value)).collect(),
  277. tekked: other.tekked,
  278. }
  279. }
  280. }
  281. impl From<PgWeapon> for weapon::Weapon {
  282. fn from(other: PgWeapon) -> weapon::Weapon {
  283. let mut attrs: [Option<weapon::WeaponAttribute>; 3] = [None; 3];
  284. for (attr, (atype, value)) in attrs.iter_mut().zip(other.attrs.iter()) {
  285. *attr = Some(weapon::WeaponAttribute {
  286. attr: *atype,
  287. value: *value
  288. });
  289. }
  290. weapon::Weapon {
  291. weapon: other.weapon,
  292. special: other.special,
  293. grind: other.grind,
  294. attrs,
  295. tekked: other.tekked,
  296. }
  297. }
  298. }
  299. #[derive(Debug, sqlx::FromRow)]
  300. pub struct PgWeaponModifier {
  301. pub weapon: i32,
  302. pub modifier: sqlx::types::Json<weapon::WeaponModifier>,
  303. }
  304. #[derive(Debug, Serialize, Deserialize)]
  305. pub struct PgArmor {
  306. armor: armor::ArmorType,
  307. dfp: u8,
  308. evp: u8,
  309. slots: u8,
  310. }
  311. impl From<armor::Armor> for PgArmor {
  312. fn from(other: armor::Armor) -> PgArmor {
  313. PgArmor {
  314. armor: other.armor,
  315. dfp: other.dfp,
  316. evp: other.evp,
  317. slots: other.slots,
  318. }
  319. }
  320. }
  321. impl From<PgArmor> for armor::Armor {
  322. fn from(other: PgArmor) -> armor::Armor {
  323. armor::Armor {
  324. armor: other.armor,
  325. dfp: other.dfp,
  326. evp: other.evp,
  327. slots: other.slots,
  328. }
  329. }
  330. }
  331. #[derive(Debug, Serialize, Deserialize)]
  332. pub struct PgShield {
  333. shield: shield::ShieldType,
  334. dfp: u8,
  335. evp: u8,
  336. }
  337. impl From<shield::Shield> for PgShield {
  338. fn from(other: shield::Shield) -> PgShield {
  339. PgShield {
  340. shield: other.shield,
  341. dfp: other.dfp,
  342. evp: other.evp,
  343. }
  344. }
  345. }
  346. impl From<PgShield> for shield::Shield {
  347. fn from(other: PgShield) -> shield::Shield {
  348. shield::Shield {
  349. shield: other.shield,
  350. dfp: other.dfp,
  351. evp: other.evp,
  352. }
  353. }
  354. }
  355. #[derive(Debug, Serialize, Deserialize)]
  356. pub struct PgUnit {
  357. unit: unit::UnitType,
  358. modifier: Option<unit::UnitModifier>,
  359. }
  360. impl From<unit::Unit> for PgUnit {
  361. fn from(other: unit::Unit) -> PgUnit {
  362. PgUnit {
  363. unit: other.unit,
  364. modifier: other.modifier,
  365. }
  366. }
  367. }
  368. impl From<PgUnit> for unit::Unit {
  369. fn from(other: PgUnit) -> unit::Unit {
  370. unit::Unit {
  371. unit: other.unit,
  372. modifier: other.modifier,
  373. }
  374. }
  375. }
  376. #[derive(Debug, Serialize, Deserialize)]
  377. pub struct PgTool {
  378. pub tool: tool::ToolType,
  379. }
  380. impl From<tool::Tool> for PgTool {
  381. fn from(other: tool::Tool) -> PgTool {
  382. PgTool {
  383. tool: other.tool,
  384. }
  385. }
  386. }
  387. impl From<PgTool> for tool::Tool {
  388. fn from(other: PgTool) -> tool::Tool {
  389. tool::Tool {
  390. tool: other.tool,
  391. }
  392. }
  393. }
  394. #[derive(Debug, Serialize, Deserialize)]
  395. pub struct PgTechDisk {
  396. tech: tech::Technique,
  397. level: u32,
  398. }
  399. impl From<tech::TechniqueDisk> for PgTechDisk {
  400. fn from(other: tech::TechniqueDisk) -> PgTechDisk {
  401. PgTechDisk {
  402. tech: other.tech,
  403. level: other.level,
  404. }
  405. }
  406. }
  407. impl From<PgTechDisk> for tech::TechniqueDisk {
  408. fn from(other: PgTechDisk) -> tech::TechniqueDisk {
  409. tech::TechniqueDisk {
  410. tech: other.tech,
  411. level: other.level
  412. }
  413. }
  414. }
  415. #[derive(Debug, Serialize, Deserialize)]
  416. pub struct PgMag {
  417. mag: mag::MagType,
  418. synchro: u8,
  419. color: u8,
  420. }
  421. impl From<mag::Mag> for PgMag {
  422. fn from(other: mag::Mag) -> PgMag {
  423. PgMag {
  424. mag: other.mag,
  425. synchro: other.synchro,
  426. color: other.color,
  427. }
  428. }
  429. }
  430. impl From<PgMag> for mag::Mag {
  431. fn from(other: PgMag) -> mag::Mag {
  432. /*mag::Mag {
  433. mag: self.mag,
  434. synchro: self.synchro,
  435. color: self.color,
  436. def: 500,
  437. pow: 0,
  438. dex: 0,
  439. mnd: 0,
  440. iq: 0,
  441. photon_blast: [None; 3],
  442. class: CharacterClass::HUmar,
  443. id: SectionID::Viridia,
  444. }*/
  445. let mut mag = mag::Mag::baby_mag(other.color as u16);
  446. mag.mag = other.mag;
  447. mag.synchro = other.synchro;
  448. mag
  449. }
  450. }
  451. #[derive(Debug, Serialize, Deserialize)]
  452. pub struct PgESWeapon {
  453. esweapon: esweapon::ESWeaponType,
  454. special: Option<esweapon::ESWeaponSpecial>,
  455. name: String,
  456. grind: u8,
  457. }
  458. impl From<esweapon::ESWeapon> for PgESWeapon {
  459. fn from(other: esweapon::ESWeapon) -> PgESWeapon {
  460. PgESWeapon {
  461. esweapon: other.esweapon,
  462. special: other.special,
  463. name: other.name,
  464. grind: other.grind,
  465. }
  466. }
  467. }
  468. impl From<PgESWeapon> for esweapon::ESWeapon {
  469. fn from(other: PgESWeapon) -> esweapon::ESWeapon {
  470. esweapon::ESWeapon {
  471. esweapon: other.esweapon,
  472. special: other.special,
  473. name: other.name,
  474. grind: other.grind,
  475. }
  476. }
  477. }
  478. #[derive(Debug, Serialize, Deserialize)]
  479. pub enum PgItemDetail {
  480. Weapon(PgWeapon),
  481. Armor(PgArmor),
  482. Shield(PgShield),
  483. Unit(PgUnit),
  484. Tool(PgTool),
  485. TechDisk(PgTechDisk),
  486. Mag(PgMag),
  487. ESWeapon(PgESWeapon),
  488. }
  489. impl From<ItemDetail> for PgItemDetail {
  490. fn from(other: ItemDetail) -> PgItemDetail {
  491. match other {
  492. ItemDetail::Weapon(weapon) => PgItemDetail::Weapon(weapon.into()),
  493. ItemDetail::Armor(armor) => PgItemDetail::Armor(armor.into()),
  494. ItemDetail::Shield(shield) => PgItemDetail::Shield(shield.into()),
  495. ItemDetail::Unit(unit) => PgItemDetail::Unit(unit.into()),
  496. ItemDetail::Tool(tool) => PgItemDetail::Tool(tool.into()),
  497. ItemDetail::TechniqueDisk(tech_disk) => PgItemDetail::TechDisk(tech_disk.into()),
  498. ItemDetail::Mag(mag) => PgItemDetail::Mag(mag.into()),
  499. ItemDetail::ESWeapon(esweapon) => PgItemDetail::ESWeapon(esweapon.into()),
  500. }
  501. }
  502. }
  503. impl From<PgItemDetail> for ItemDetail {
  504. fn from(other: PgItemDetail) -> ItemDetail {
  505. match other {
  506. PgItemDetail::Weapon(weapon) => ItemDetail::Weapon(weapon.into()),
  507. PgItemDetail::Armor(armor) => ItemDetail::Armor(armor.into()),
  508. PgItemDetail::Shield(shield) => ItemDetail::Shield(shield.into()),
  509. PgItemDetail::Unit(unit) => ItemDetail::Unit(unit.into()),
  510. PgItemDetail::Tool(tool) => ItemDetail::Tool(tool.into()),
  511. PgItemDetail::TechDisk(tech_disk) => ItemDetail::TechniqueDisk(tech_disk.into()),
  512. PgItemDetail::Mag(mag) => ItemDetail::Mag(mag.into()),
  513. PgItemDetail::ESWeapon(esweapon) => ItemDetail::ESWeapon(esweapon.into()),
  514. }
  515. }
  516. }
  517. #[derive(Debug, sqlx::FromRow)]
  518. pub struct PgItem {
  519. pub id: i32,
  520. pub item: sqlx::types::Json<PgItemDetail>,
  521. }
  522. #[derive(Debug, Serialize, Deserialize)]
  523. pub enum PgItemNoteDetail {
  524. CharacterCreation {
  525. character_id: u32,
  526. },
  527. EnemyDrop {
  528. character_id: u32,
  529. room_id: u32,
  530. monster_type: MonsterType,
  531. map_area: MapArea,
  532. x: f32,
  533. y: f32,
  534. z: f32,
  535. },
  536. BoxDrop {
  537. character_id: u32,
  538. room_id: u32,
  539. map_area: MapArea,
  540. x: f32,
  541. y: f32,
  542. z: f32,
  543. },
  544. Pickup {
  545. character_id: u32,
  546. },
  547. PlayerDrop {
  548. character_id: u32,
  549. map_area: MapArea,
  550. x: f32,
  551. y: f32,
  552. z: f32,
  553. },
  554. Consumed {
  555. character_id: u32,
  556. },
  557. FedToMag {
  558. character_id: u32,
  559. mag: u32,
  560. },
  561. BoughtAtShop {
  562. character_id: u32,
  563. },
  564. SoldToShop {
  565. character_id: u32,
  566. },
  567. Trade {
  568. trade_id: u32,
  569. character_to: u32,
  570. character_from: u32,
  571. },
  572. Withdraw {
  573. character_id: u32,
  574. bank: BankIdentifier,
  575. },
  576. Deposit {
  577. character_id: u32,
  578. bank: BankIdentifier,
  579. },
  580. FloorLimitReached {
  581. map_area: MapArea,
  582. }
  583. }
  584. impl From<ItemNote> for PgItemNoteDetail {
  585. fn from(other: ItemNote) -> PgItemNoteDetail {
  586. match other {
  587. ItemNote::CharacterCreation{character_id} => PgItemNoteDetail::CharacterCreation {
  588. character_id: character_id.0,
  589. },
  590. ItemNote::EnemyDrop{character_id, room_id, monster_type, map_area, x, y, z} => PgItemNoteDetail::EnemyDrop {
  591. character_id: character_id.0,
  592. room_id: room_id.0,
  593. monster_type,
  594. map_area,
  595. x,y,z,
  596. },
  597. ItemNote::BoxDrop{character_id, room_id, map_area, x, y, z} => PgItemNoteDetail::BoxDrop {
  598. character_id: character_id.0,
  599. room_id: room_id.0,
  600. map_area,
  601. x,y,z,
  602. },
  603. ItemNote::Pickup{character_id} => PgItemNoteDetail::Pickup {
  604. character_id: character_id.0,
  605. },
  606. ItemNote::PlayerDrop{character_id, map_area, x, y, z} => PgItemNoteDetail::PlayerDrop {
  607. character_id: character_id.0,
  608. map_area,
  609. x,y,z,
  610. },
  611. ItemNote::Consumed{character_id} => PgItemNoteDetail::Consumed {
  612. character_id: character_id.0,
  613. },
  614. ItemNote::FedToMag{character_id, mag} => PgItemNoteDetail::FedToMag{
  615. character_id: character_id.0,
  616. mag: mag.0
  617. },
  618. ItemNote::BoughtAtShop{character_id} => PgItemNoteDetail::BoughtAtShop {
  619. character_id: character_id.0,
  620. },
  621. ItemNote::SoldToShop{character_id} => PgItemNoteDetail::SoldToShop {
  622. character_id: character_id.0,
  623. },
  624. ItemNote::Trade{trade_id, character_to, character_from} => PgItemNoteDetail::Trade {
  625. trade_id: trade_id.0,
  626. character_to: character_to.0,
  627. character_from: character_from.0,
  628. },
  629. ItemNote::Withdraw{character_id, bank} => {
  630. PgItemNoteDetail::Withdraw {
  631. character_id: character_id.0,
  632. bank,
  633. }
  634. },
  635. ItemNote::Deposit{character_id, bank} => {
  636. PgItemNoteDetail::Deposit {
  637. character_id: character_id.0,
  638. bank,
  639. }
  640. },
  641. ItemNote::FloorLimitReached { map_area } => {
  642. PgItemNoteDetail::FloorLimitReached {
  643. map_area,
  644. }
  645. },
  646. }
  647. }
  648. }
  649. impl From<PgItemNoteDetail> for ItemNote {
  650. fn from(other: PgItemNoteDetail) -> ItemNote {
  651. match other {
  652. PgItemNoteDetail::CharacterCreation{character_id} => ItemNote::CharacterCreation {
  653. character_id: CharacterEntityId(character_id),
  654. },
  655. PgItemNoteDetail::EnemyDrop{character_id, room_id, monster_type, map_area, x, y, z} => ItemNote::EnemyDrop {
  656. character_id: CharacterEntityId(character_id),
  657. room_id: RoomEntityId(room_id),
  658. monster_type,
  659. map_area,
  660. x,y,z,
  661. },
  662. PgItemNoteDetail::BoxDrop{character_id, room_id, map_area, x, y, z} => ItemNote::BoxDrop {
  663. character_id: CharacterEntityId(character_id),
  664. room_id: RoomEntityId(room_id),
  665. map_area,
  666. x,y,z,
  667. },
  668. PgItemNoteDetail::Pickup{character_id} => ItemNote::Pickup {
  669. character_id: CharacterEntityId(character_id),
  670. },
  671. PgItemNoteDetail::PlayerDrop{character_id, map_area, x, y, z} => ItemNote::PlayerDrop {
  672. character_id: CharacterEntityId(character_id),
  673. map_area,
  674. x,y,z,
  675. },
  676. PgItemNoteDetail::Consumed{character_id} => ItemNote::Consumed {
  677. character_id: CharacterEntityId(character_id),
  678. },
  679. PgItemNoteDetail::FedToMag{character_id, mag} => ItemNote::FedToMag{
  680. character_id: CharacterEntityId(character_id),
  681. mag: ItemEntityId(mag)
  682. },
  683. PgItemNoteDetail::BoughtAtShop{character_id} => ItemNote::BoughtAtShop {
  684. character_id: CharacterEntityId(character_id),
  685. },
  686. PgItemNoteDetail::SoldToShop{character_id} => ItemNote::SoldToShop {
  687. character_id: CharacterEntityId(character_id),
  688. },
  689. PgItemNoteDetail::Trade {trade_id, character_to, character_from} => ItemNote::Trade {
  690. trade_id: TradeId(trade_id),
  691. character_to: CharacterEntityId(character_to),
  692. character_from: CharacterEntityId(character_from),
  693. },
  694. PgItemNoteDetail::Withdraw{character_id, bank} => ItemNote::Withdraw {
  695. character_id: CharacterEntityId(character_id),
  696. bank,
  697. },
  698. PgItemNoteDetail::Deposit{character_id, bank} => ItemNote::Deposit {
  699. character_id: CharacterEntityId(character_id),
  700. bank,
  701. },
  702. PgItemNoteDetail::FloorLimitReached { map_area } => ItemNote::FloorLimitReached {
  703. map_area,
  704. },
  705. }
  706. }
  707. }
  708. #[derive(Debug, sqlx::FromRow)]
  709. pub struct PgItemNote {
  710. //pub id: i32,
  711. pub note: sqlx::types::Json<PgItemNoteDetail>,
  712. created_at: chrono::DateTime<chrono::Utc>,
  713. }
  714. #[derive(Debug, Serialize, Deserialize)]
  715. pub enum PgMagModifierDetail {
  716. FeedMag(i32),
  717. BankMag,
  718. MagCell(i32),
  719. OwnerChange(CharacterClass, SectionID)
  720. }
  721. impl From<mag::MagModifier> for PgMagModifierDetail {
  722. fn from(other: mag::MagModifier) -> PgMagModifierDetail {
  723. match other {
  724. mag::MagModifier::FeedMag{food} => PgMagModifierDetail::FeedMag(food.0 as i32),
  725. mag::MagModifier::BankMag => PgMagModifierDetail::BankMag,
  726. mag::MagModifier::MagCell(cell) => PgMagModifierDetail::MagCell(cell.0 as i32),
  727. mag::MagModifier::OwnerChange(class, section_id) => PgMagModifierDetail::OwnerChange(class, section_id),
  728. }
  729. }
  730. }
  731. impl From<PgMagModifierDetail> for mag::MagModifier {
  732. fn from(other: PgMagModifierDetail) -> mag::MagModifier {
  733. match other {
  734. PgMagModifierDetail::FeedMag(food) => mag::MagModifier::FeedMag{food: ItemEntityId(food as u32)},
  735. PgMagModifierDetail::BankMag => mag::MagModifier::BankMag,
  736. PgMagModifierDetail::MagCell(cell) => mag::MagModifier::MagCell(ItemEntityId(cell as u32)),
  737. PgMagModifierDetail::OwnerChange(class, section_id) => mag::MagModifier::OwnerChange(class, section_id),
  738. }
  739. }
  740. }
  741. #[derive(Debug, sqlx::FromRow)]
  742. pub struct PgMagModifier {
  743. mag: i32,
  744. pub modifier: sqlx::types::Json<PgMagModifierDetail>,
  745. created_at: chrono::DateTime<chrono::Utc>,
  746. }
  747. #[derive(Debug, sqlx::FromRow)]
  748. pub struct PgItemEntity {
  749. pub id: i32,
  750. pub item: sqlx::types::Json<PgItemDetail>,
  751. }
  752. /*
  753. #[derive(Debug, sqlx::FromRow)]
  754. pub struct PgItemWithLocation {
  755. pub id: i32,
  756. pub item: sqlx::types::Json<PgItemDetail>,
  757. pub location: sqlx::types::Json<PgItemLocationDetail>,
  758. }
  759. */
  760. impl From<PgItemEntity> for ItemEntity {
  761. fn from(other: PgItemEntity) -> ItemEntity {
  762. ItemEntity {
  763. id: ItemEntityId(other.id as u32),
  764. item: other.item.0.into(),
  765. }
  766. }
  767. }
  768. #[derive(Debug, sqlx::FromRow)]
  769. pub struct PgMagModifierWithParameters {
  770. pub mag: i32,
  771. pub modifier: sqlx::types::Json<PgMagModifierDetail>,
  772. pub feed: Option<sqlx::types::Json<PgTool>>,
  773. pub cell: Option<sqlx::types::Json<PgTool>>,
  774. }
  775. #[derive(Debug, Serialize, Deserialize)]
  776. #[serde(untagged)]
  777. pub enum PgInventoryItemEntity {
  778. Individual(i32),
  779. Stacked(Vec<i32>),
  780. }
  781. #[derive(Debug, sqlx::FromRow)]
  782. pub struct PgInventoryEntity {
  783. pub pchar: i32,
  784. pub items: sqlx::types::Json<Vec<PgInventoryItemEntity>>,
  785. }
  786. #[derive(Debug, sqlx::FromRow)]
  787. pub struct PgBankEntity {
  788. pub pchar: i32,
  789. pub items: sqlx::types::Json<Vec<PgInventoryItemEntity>>,
  790. pub name: String,
  791. }
  792. #[derive(Debug, sqlx::FromRow)]
  793. pub struct PgEquipped {
  794. pchar: i32,
  795. weapon: Option<i32>,
  796. armor: Option<i32>,
  797. shield: Option<i32>,
  798. unit0: Option<i32>,
  799. unit1: Option<i32>,
  800. unit2: Option<i32>,
  801. unit3: Option<i32>,
  802. mag: Option<i32>,
  803. }
  804. impl From<PgEquipped> for EquippedEntity{
  805. fn from(other: PgEquipped) -> EquippedEntity {
  806. EquippedEntity {
  807. weapon: other.weapon.map(|i| ItemEntityId(i as u32)),
  808. armor: other.armor.map(|i| ItemEntityId(i as u32)),
  809. shield: other.shield.map(|i| ItemEntityId(i as u32)),
  810. unit: [other.unit0.map(|i| ItemEntityId(i as u32)),
  811. other.unit1.map(|i| ItemEntityId(i as u32)),
  812. other.unit2.map(|i| ItemEntityId(i as u32)),
  813. other.unit3.map(|i| ItemEntityId(i as u32)),
  814. ],
  815. mag: other.mag.map(|i| ItemEntityId(i as u32)),
  816. }
  817. }
  818. }
  819. impl From<(CharacterEntityId, EquippedEntity)> for PgEquipped {
  820. fn from(char_equips: (CharacterEntityId, EquippedEntity)) -> PgEquipped {
  821. PgEquipped {
  822. pchar: (char_equips.0).0 as i32,
  823. weapon: char_equips.1.weapon.map(|i| i.0 as i32),
  824. armor: char_equips.1.armor.map(|i| i.0 as i32),
  825. shield: char_equips.1.shield.map(|i| i.0 as i32),
  826. unit0: char_equips.1.unit[0].map(|i| i.0 as i32),
  827. unit1: char_equips.1.unit[1].map(|i| i.0 as i32),
  828. unit2: char_equips.1.unit[2].map(|i| i.0 as i32),
  829. unit3: char_equips.1.unit[3].map(|i| i.0 as i32),
  830. mag: char_equips.1.mag.map(|i| i.0 as i32),
  831. }
  832. }
  833. }
  834. #[derive(Debug, sqlx::FromRow)]
  835. pub struct PgTradeEntity {
  836. id: i32,
  837. character1: i32,
  838. character2: i32,
  839. }
  840. impl From<PgTradeEntity> for TradeEntity {
  841. fn from(other: PgTradeEntity) -> TradeEntity {
  842. TradeEntity {
  843. id: TradeId(other.id as u32),
  844. character1: CharacterEntityId(other.character1 as u32),
  845. character2: CharacterEntityId(other.character2 as u32),
  846. }
  847. }
  848. }
  849. #[derive(Debug, sqlx::FromRow, Serialize)]
  850. pub struct PgRoomEntity {
  851. id: i32,
  852. name: String,
  853. section_id: i8,
  854. mode: i8,
  855. episode: i8,
  856. difficulty: i8,
  857. }
  858. impl From<PgRoomEntity> for RoomEntity {
  859. fn from(other: PgRoomEntity) -> RoomEntity {
  860. RoomEntity {
  861. id: RoomEntityId(other.id as u32),
  862. name: other.name,
  863. section_id: SectionID::from(other.section_id as u8),
  864. mode: RoomEntityMode::from(other.mode as u8),
  865. episode: Episode::try_from(other.episode as u8).unwrap(),
  866. difficulty: Difficulty::try_from(other.difficulty as u8).unwrap(),
  867. }
  868. }
  869. }