Initial Commit

This commit is contained in:
rubenwardy 2014-04-13 18:57:19 +01:00
commit c21b722e6d
3 changed files with 334 additions and 0 deletions

22
.gitattributes vendored Normal file
View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

215
.gitignore vendored Normal file
View File

@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

97
init.lua Normal file
View File

@ -0,0 +1,97 @@
diet = {
players = {}
}
function diet.item_eat(max)
return function(itemstack, user, pointed_thing)
-- Process player data
local name = user:get_player_name()
local player = diet.__player(name)
local item = itemstack:get_name()
-- Get type
local ftype = ""
if (minetest.registered_items[item] and minetest.registered_items[item].groups) then
local groups = minetest.registered_items[item].groups
if groups.food_type_meal then
ftype = "meal"
elseif groups.food_type_snack then
ftype = "snack"
elseif groups.food_type_dessert then
ftype = "dessert"
elseif groups.food_type_drink then
ftype = "drink"
end
end
-- Calculate points
local points = max
if (#player.eaten>0) then
local same_food = 0
local same_type = 0
for _,v in pairs(player.eaten) do
if v[1] == item then
same_food = same_food + 1
end
if v[2] == ftype then
same_type = same_type + 1
end
end
local mult = same_food/10
points = points * 1-mult
if (mult > 0.9) then
local desc = item
if (minetest.registered_items[item] and minetest.registered_items[item].description) then
desc = minetest.registered_items[item].description
end
minetest.chat_send_player(name,"Your stomach hates "..desc)
elseif (mult > 0.4) then
minetest.chat_send_player(name,"Your stomach could do with a change.")
end
if points > max then
error("[DIET] This shouldn't happen! points > max")
return
end
end
-- Increase health
local hp = user:get_hp()
if (hp+points > 20) then
hp = 20
else
hp = hp + points
end
user:set_hp(hp)
-- Register
diet.__register_eat(player,item,ftype)
-- Remove item
itemstack:take_item()
return itemstack
end
end
function diet.__player(name)
if name == "" then
return nil
end
if diet.players[name] then
return diet.players[name]
end
diet.players[name] = {
name = name,
eaten = {}
}
return diet.players[name]
end
function diet.__register_eat(player,food,type)
table.insert(player.eaten,{food,type})
while (#player.eaten > 10) do
table.remove(player.eaten,1)
end
end