Coder Social home page Coder Social logo

drapedotnet's Introduction

Drape

Drape is C# data-driven modeling framework for game stats/attributes. It is being developed for Unity but is not Unity dependent, thus can be used without it.

Important It is work in progress and current API is subject to change.

Motivation

Drape has been started as a side project facilitating management of numeric game stats. Main requirement was ability to create and register stats that then could be dynamically modified with stat modifier objects.

Goals

  • Flexibility
  • Extendability
  • Small footprint
  • Performance

Features

  • Creating stats from code
  • Stat registration and retrieval
  • Dynamically calculated stat values
  • Modifying stats with stat modifiers
  • Local stat
  • Creating stats using data files
    • JSON support
    • YAML support

Stat types

  • Stat (simple stat)
  • Modifier
  • Resource
  • Multistat

Stat formulas

Stat and modifiers

Stat components
---------------
B - base value
R - raw modifier
F - final modifier

Modifier types
---------------
f - flat
m - multiplier

Raw value formula
-----------------
R = (B + Rf) * Rm
Rf = Rf(a) + Rf(l) + Rf(g) + … + Rf(x)
Rm = Rm(a) + Rm(l) + Rm(g) + … + Rm(y)

Final value formula
-------------------
F = (R + Ff) * Fm
Ff = Ff(a) + Ff(l) + Ff(g) + …. + Ff(x)
Fm = 1 + Fm(a) + Ff(l) + Ff(g) + … + Ff(x)

Serialization

Json

JSON serialization supported with SaladLab fork of Newtonsoft Json.NET. You can get latest DLL file from here.

Private setter serialization supported with custom contract resolver method as described in Daniel's blog.

Yaml

Yaml serialization supported with YamlDotNet. Get latest release dll from here.

Consideration

  • What is the reason of using final stat modifier (F)? Is it needed at all?
  • BaseStatData.ToJSON() method only serializes public properties and doesn't allow to serialize members.
  • Is BaseStatData needed? Can Stat be serialized directly?
  • Applying global modifier to multiple stats of same type not supported. Eg. improved melee damage should apply to all melee damage type stats: sword damage, axe damage, etc.

Project setup

  1. Clone repository
  2. Open it from unity
    • Ignore console errors. You need to build it .dll.
    • Let unity create .sln solution file and open it from Visual Studio
  3. Add ./Drape.Source/Drape.Source.csproj (existing project) to the solution
  4. Build added Drape.Source project.

drapedotnet's People

Contributors

fullstackforger avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

fullstackforger

drapedotnet's Issues

Registry factory constructor should allow single installer as a argument.

RegistryFactory registryFactory = new RegistryFactory(new List<IInstaller>() {
	{ new YamlInstaller<Stat, StatData>((Resources.Load("example03/stats") as TextAsset).text) },
	{ new YamlInstaller<Resource, ResourceData>((Resources.Load("example03/resources") as TextAsset).text) },
	{ new YamlInstaller<Modifier, ModifierData>((Resources.Load("example03/modifiers") as TextAsset).text) },
});

Should work with

RegistryFactory registryFactory = new RegistryFactory(new YamlInstaller<Stat, StatData>((Resources.Load("example03/stats") as TextAsset).text));

Factor error

Factors should be added together before multiplication

Local stat dependencies limitations

Currently stat dependencies can't be modified. It works ok for RPG like dependent properties, eg:
_ melee damage -> strength _

Local stats, however, since are created on the fly should have local dependencies. Framework doesn't allow that. To fix the problem in Forsaken Expanse I have introduced few modifications to the framework.

Problem with local stats

Currently if different entities need stat with the same id,, each of the entities would have to use own stat registry, which makes it difficult to apply common modifier to all of them. It requires manual intervention.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.