Skip to content

Property Model #15

@blurbeast

Description

@blurbeast

📌 Feature Request: Full Implementation of PropertyTrait for Game Property Logic


🧩 Description

Implement the full logic for all methods defined in the PropertyTrait within the PropertyImpl. This trait governs all interactions and transformations related to in-game properties such as ownership transfer, rent calculations, mortgage status, and development (upgrade/downgrade).

The current implementation provides a basic structure but lacks concrete logic in critical functions like upgrades, downgrades, and ownership changes. These need to be handled with proper validation and state updates.


🧠 Model Overview

#[dojo::model]
pub struct Property {
    #[key]
    pub id: u8,
    #[key]
    pub game_id: u256,
    pub name: felt252,
    pub owner: ContractAddress,
    pub cost_of_property: u256,
    pub property_level: u8,
    pub rent_site_only: u256,
    pub rent_one_house: u256,
    pub rent_two_houses: u256,
    pub rent_three_houses: u256,
    pub rent_four_houses: u256,
    pub cost_of_house: u256,
    pub rent_hotel: u256,
    pub is_mortgaged: bool,
    pub group_id: u8,
    pub for_sale: bool,
    pub development: u8,
}

✅ Acceptance Criteria

  • get_rent_amount() correctly computes rent based on development level (houses/hotel), returning 0 if the property is mortgaged.

  • mortgage() and lift_mortgage() toggle the is_mortgaged flag correctly.

  • upgrade_property():

    • Can only be called by the current property owner.
    • Fails if upgrade level exceeds max (usually 4 or 5).
    • Increments property_level and updates development.
    • Validates that the property is not mortgaged.
  • downgrade_property():

    • Can only be called by the current property owner.
    • Fails if property_level is already zero.
    • Decrements property_level and adjusts development.
  • change_game_property_ownership():

    • Can only be called by the current owner.
    • Transfers the ownership to new_owner.
    • Ensures property is not mortgaged and is marked for_sale.

🛠️ Implementation Notes

fn upgrade_property(ref self: Property, player: ContractAddress, upgrade_level: u8) -> bool {
    if self.owner != player || self.is_mortgaged {
        return false;
    }
    if self.property_level + upgrade_level > 5 {
        return false;
    }
    self.property_level += upgrade_level;
    self.development += upgrade_level;
    true
}

fn downgrade_property(ref self: Property, player: ContractAddress, downgrade_level: u8) -> bool {
    if self.owner != player || self.property_level < downgrade_level {
        return false;
    }
    self.property_level -= downgrade_level;
    self.development -= downgrade_level;
    true
}

fn change_game_property_ownership(ref self: Property, new_owner: ContractAddress, owner: ContractAddress) -> bool {
    if self.owner != owner || self.is_mortgaged == true || self.for_sale == false {
        return false;
    }
    self.owner = new_owner;
    self.for_sale = false;
    true
}

🧪 Testing Notes

  • Rent Test: Ensure correct rent is returned for each development level.
  • Mortgage Test: Mortgage and lift mortgage reflect correctly in state.
  • Upgrade Test: Upgrade only works for owner and within bounds.
  • Downgrade Test: Prevents reducing below zero or by non-owner.
  • Ownership Transfer Test: Only original owner can transfer, and only if conditions are met.

📘 Status

Stat: 🔄 Pending Implementation
Build: 🔲 To Be Confirmed
Validation: 🔲 Functional Logic Pending


📎 Additional Notes

  • Consider emitting events for upgrades, downgrades, and ownership transfers for transparency.
  • Guard against overflows on development and property_level.
  • Potential for adding auction mechanism for unowned properties in future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions