---
# System prepended metadata

title: Zone RPG

---

# Zone RPG




```
-------------------------------|
|                       #      |
|                       #      |
|                       #      |
|                     X #    D |  
|                       M      |
|                       #      |
-------------------------------|

----------------|
| Weapon: Rusty sword     // länkas via Player.weapon_id
| Boots:  None     
| Helm:   None
---------
  Inventory:       
     <Item>
     <Item>
     <Item>  


input

1. attack


(I = Item)
x = player
M = Monster  ->  Item
D = Door
# / | = Vägg

```

* När player är nära monstret, slåss de automatiskt.
* Om man besegrar monstret, spawnas loot (Item).
* Man får välja vilka items man vill plocka upp

### Spelstart
* Spelaren får välja vilken klass de vill ha
* 

### Items:
* "Item" är ett verkligt exemplar i världen
* "ItemInfo" håller "meta"-information om vapnet, (namn osv "Rusty sword", "Old boots")
* "ItemType" är klassifikationen av item, tex "Vapen, Boots, "
* Vi länkar player och vapen åt båda håll




### Classer i C#

```plantuml
enum CharacterClass{
    Warrior, 
    Mage,
    Druid
}

class Entity {
    int zon_id;
    int x;
    int y;
    char symbol;
    int hp;
}

class ZonObject {
    Kan vara Sten, träd, dörr
}


class CharacterController{
    MoveCharacter();
}

class Monster {
   int attack;
}

class Player {
    int xp = 0;
    Skill[] skills;
    CharacterClass characterClass
}

class Item {
    ItemType
}

class ItemType {
    
}

class Zone {
    Descrption
    
}

class FightManager {
    
    Fight(Character player, Character Monster);
}

class LootGenerator {
    Vars enda uppgift är att skapa loot, 
    t.ex. från ett monster (eller monster typ)
    --
    CreateLoot();
    CreateLoot(Character monster); 
}

class Ui{
    DrawMap();
    Här hamnar ALL Console.Write
}

class Database {
    
}




Zone --> Entity : Innehåller
Player --> Item : Kan ha många
Item --> ItemType : IsOne
Player::CharacterClass --> CharacterClass : Has One
Entity <|-- ZonObject
Entity <|--  Monster : Inherits from
Entity <|--  Player : Inherits from

Ui --> Database : Uses
Ui --> FightManager : Uses
Ui --> CharacterController : Uses
Ui --> LootGenerator: Uses


```

## Databasdiagram
```plantuml
    Object Zone {
        id   INTEGER
        name VARCHAR(20)    
    }
    
    Object Entity {
        id INTEGER
        zone_id INTEGER
        x  INTEGER
        y  INTEGER
        health   
    }


    Object Player {
        id
        entity_id INTEGER
        character_class_id
        name VARCHAR
        xp INTEGER
        is_mob BOOL
        item_id_weapon
        item_id_boots
        item_id_helm
    }

    Object Skill{
        id INTEGER
        name VARCHAR
    }

    Object player_to_skill{
        player_id
        skill_id
        
    }

    Object Item{
        id
        player_id
        item_info_id
    }

    Object ItemInfo {
        id
        name
        item_type_id
    }

    Object ItemType{
        id
        name
    }

    Object ZoneObject{
        id INTEGER
        entity_id INTEGER
        name VARCHAR
     }

    Object CharacterClass{
        id
        name
    }

    


    Entity::zone_id --> Zone::id
    
      
    Item::player_id --> Player::id
    Item::item_info_id --> ItemInfo::id
    ItemInfo::item_type_id --> ItemType::id
    Player::character_class_id -> CharacterClass::id
    ZoneObject::entity_id --> Entity::id
    Player::entity_id -> Entity::id
    Player::item_id_boots --> Item::id
    Player::id <-- player_to_skill::player_id
    player_to_skill::skill_id --> Skill::id
    
```

## Exempel   (PSEUDOKOD)
```
// Skapa loot
var item = new Item();
player.items.Add(item);

// Minimal editor
Skapa nytt object?
Monster / Sten / Träd
Zon: 41
x: 5
y: 23
save!
``` 




### Draw map  (PSEUDOKOD)

``` 
// Exemple på att hämta zon-object
"SELECT * from Entity WHERE Zon = 41";

ZonObject zo = new();
foreach (var e in entities)
Console.SetPosition(10, 20);
if (zo.type = "STONE"){
   Console.SetColor(GREEN);
   Console.Write("#");
}
if (zo.type = "MONSTER"){
   Console.SetColor(RED);
   Console.Write("M");
}
``` 

# Inventory

### Item
| id | Player_id | ItemType_id |
| -------- | -------- | -------- |
| 1     | 5     | 19     |
| 2     | 5     | 18    |
| 3     | 9     | 12     |
| 4     | 1     | 6     |

### Player inventory
| id | Player_id | ItemType_id |
| -------- | -------- | -------- |
| 1     | 5     | 19     |
| 2     | 5     | 18    |
| 3     | 9     | 12     |
| 4     | 1     | 6     |



## Databasdiagram (nytt)
```plantuml
    Object Zone {
        id   INTEGER
        name VARCHAR(20)    
    }
    
    Object Entity {
        id INTEGER
        zone_id INTEGER
        x  INTEGER
        y  INTEGER
        health
        entity_type_id
    }
    
     Object Entity_type{
         id
         name
    }


    Object Character {
        id
        entity_id INTEGER
        character_class_id
        name VARCHAR
        xp INTEGER
        weapon_id
        boots_id
        helm_id
    }



    Object Item{
        id
        player_id
        item_info_id
    }

    Object ItemInfo {
        id
        name
        item_type_id
    }

    Object ItemType{
        id
        name
    }


    Object CharacterClass{
        id
        name
        base_attack
        base_defense
        base_defense_per_level
        base_attack_per_level
        max_hp
        max_hp_per_level
    }
    
    Object MonsterClass{
        id
        name
        base_attack
        base_attack_per_level
        max_hp
        max_hp_per_level
        type
}
    
     Object Door{
         id
         entity_id
         target_zone_id
         target_x
         target_y
}

     Object Message{
        character_id
        text
        datetime
    }



    Zone::id <-- Entity::zone_id       
    Item::player_id --> Character::id
    Item::item_info_id --> ItemInfo::id
    ItemInfo::item_type_id --> ItemType::id
    Character::character_class_id -> CharacterClass::id
    Character::character_class_id -> MonsterClass::id
    Character::entity_id --> Entity::id
    Door::entity_id -> Entity::id
    Entity::entity_type_id --> Entity_type::id
    Character::item_id_boots --> Item::id
    Message::character_id --> Character::id
    
    
```