Skip to content

Instantly share code, notes, and snippets.

@oott123
Created May 8, 2014 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oott123/48249911d58ff1c47707 to your computer and use it in GitHub Desktop.
Save oott123/48249911d58ff1c47707 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id powerful-civitas
// @name 独间辅助 - c世界居民必备
// @version 1.0
// @namespace oott123_powerful_civitas
// @author oott123
// @description
// @include http://*.soobb.com/*
// @run-at document-end
// ==/UserScript==
var start = (function($){
/**
* 设置数据
* @param {string} key 数据key
* @param value 数据值
*/
function saveData(key,value){
return localStorage[key] = value;
}
/**
* 获取数据
* @param {string} key 设置的数据key
* @return 返回存档中的数据值
*/
function getData(key){
return localStorage[key];
}
//“我的状态”栏目置顶
function fixStatus(){
var fixStyle = $('<style>');
$('head').append(fixStyle);
$(window).scroll(function(){
var styleSetted = false;
if($(window).scrollTop()>=70){
if(!styleSetted){
$(fixStyle).html('#MainContent .LeftColumn .PersonalInfo{position: fixed;background-color: #F7F7F7;z-index: 3;margin-top: -65px;}#MainContent .LeftColumn .Line2:first-of-type{position: fixed;background-color: #F7F7F7;z-index: 2;}#MainContent .LeftColumn .PersonalStatus.Section{position: fixed;background-color: #F7F7F7;z-index: 1;margin: 0;margin-top: -60px;width: 150px;padding: 90px 15px 5px;}#MainContent .LeftColumn .Line2:nth-of-type(2){margin-top: 300px;}');
}
styleSetted = true;
}else{
styleSetted = false;
$(fixStyle).html('');
}
});
}
//洛阳运势
function helloLuoyang(){
if(window.location.toString().match(/\/Mine\/$/)){
var luoyang = $('<iframe>')
.attr('src','http://sandbox.runjs.cn/show/2zxw2p9l')
.attr('width','340')
.attr('frameborder','no')
.attr('border','no')
.css('margin-left','20px')
.attr('height','480');
$('.ContentColumn .Column1 .VolumeGroups').before(luoyang);
}
}
//隐藏磁贴
function hideTiles(tiles){
if(!window.location.toString().match(/\/Mine\/$/)){
return false;
}
if(tiles.indexOf('AvatarSet')>-1){
$('.AvatarSet').hide();
}
if(tiles.indexOf('Message')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-Green').hide();
}
if(tiles.indexOf('Notifications')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-Blue').hide();
}
if(tiles.indexOf('Recipes')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-RedLight').hide();
}
if(tiles.indexOf('Collections')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-Brown').hide();
}
if(tiles.indexOf('Home')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-PinkDark').hide();
}
if(tiles.indexOf('Work')>-1){
$('.ContentColumn .Column1 .Section.MetroTiles .BG-Color-Teal').hide();
}
}
//消灭自动刷新信息
function noRefreshSpeeches(){
$('#Speeches_Pushing').prop('checked',false).change();
}
function autoReadMessages(){
if(!window.location.toString().match(/Notifications/)){
return false;
}
$.get('http://civitas.soobb.com/Mine/AjaxReadNotifications/?Action=Search');
}
//更新住处信息
function updateHome(){
if(!window.location.toString().match(/\/Mine\/$/)){
return false;
}
var homeUrl = $('#MainContent .Tile.BG-Color-PinkDark').attr('href');
//街区三围,懒得写循环了……
saveData('healthIndex',$('.HealthIndex .Number').text().match(/(\d|\.)+/)[0]);
saveData('prosperityIndex',$('.ProsperityIndex .Number').text().match(/(\d|\.)+/)[0]);
saveData('industryIndex',$('.IndustryIndex .Number').text().match(/(\d|\.)+/)[0]);
$.get(homeUrl,function(text){
var $homePage = $(text);
var homeType = $homePage.find('.EstateDetails .EstateHeader .Content .Subject h3 span').text().match(/\((.*)\)/)[1];
var homeLevel = $homePage.find('.EstateDetails .EstateHeader .Subject .LevelStarLarge').attr('class').match(/\d+/)[0]/10;
saveData('homeType',homeType);
saveData('homeLevel',homeLevel);
try{
updateETD();
}catch(e){
console.log(e);
}
});
}
//获取四围
function get4(){
var attrs='Stamina,Happiness,Health,Starvation'.split(','),att={};
for(var i=0;i<attrs.length;i++){
att[attrs[i]] = parseFloat($('#Status_'+attrs[i]+' .Number').text());
saveData('now'+attrs[i],att[attrs[i]]);
}
return att;
}
//获取性格
function getChar(){
if(!window.location.toString().match(/\/Mine\/$/)){
return false;
}
for(var i=1;i<=4;i++){
saveData('char'+i,parseFloat($('.Character'+i+' .Index').text().match(/(\d|\.|\-)+/)[0]));
}
}
//更新换日后数据
function updateETD(){
//sta,hap,hea,hgr
var homeType = getData('homeType'),homeLevel = getData('homeLevel')
,att=get4(),attAfter=get4();
//计算精力
var staAff = 100,hapAff = 100,heaAff = 100,hgrAff = 100,charAff = 100,base;
//精力低于 25,精力影响指数 = (100+精力-25)%。(以下条件均指换日前数据)。高于25为1。
if(att.Stamina<25){
staAff = 100+att.Stamina-25;
}
//快乐高于 75,快乐影响指数 = (100+快乐-75)%。低于75为1。
if(att.Happiness>75){
hapAff = 100+att.Happiness-75;
}
//勤奋性格时,勤奋影响指数 = (100+25*勤奋)%。安逸性格无影响。
var char1 = parseFloat(getData('char1'));
var char3 = parseFloat(getData('char3')),charAff3=100;
if(char1>0){
charAff = 100+25*(char1/100);
}
if(char3>0){
charAff3 = 100+20*(char3/100);
}
if(att.Health<75){
//健康低于 75,健康影响指数 = (100+健康-75)%。
heaAff = 100+att.Health-75;
}else if(att.Health>90){
//健康高于 90,健康影响指数 =(100+健康-90)%。
heaAff = 100+att.Health-90;
}
//饥饿低于 75,饥饿影响指数 = (100-75+饥饿)%。高于75为1。
if(att.Starvation<75){
hgrAff = 100-75+att.Starvation;
}
//基准
switch(parseInt(homeLevel)){
case 1:
base = 32;
break;
case 2:
base = 36;
break;
}
//换日精力回复值=基准值*健康影响指数*饥饿影响指数*精力影响指数*快乐或勤奋影响指数
attAfter.Stamina=parseFloat(att.Stamina)+base*heaAff/100*hgrAff/100*staAff/100*Math.max(hapAff,charAff)/100*charAff3/100;
//console.log(base,heaAff,hgrAff,staAff,hapAff,charAff);
//健康快乐基准
base = 0;staAff = 100;hapAff = 100;heaAff = 100;hgrAff = 100;charAff = 100;
switch(homeType+homeLevel){
case '别墅1':
case 'Villa1':
base = 2;
break;
case '别墅2':
case 'Villa2':
base = 2.8;
break;
case '宅院1':
case 'House1':
base = 1.6;
break;
case '宅院2':
case 'House2':
base = 2;
break;
case '楼房1':
case 'Apartment1':
base = 1;
break;
case '楼房2':
case 'Apartment2':
base = 1.25;
break;
case '营地1':
base = 1;
break;
case '营地2':
base = 1.15;
break;
default:
console.log('无法识别住处类型,或许是未更新住处信息?',homeType,homeLevel);
return false;
}
//健康换日回复
//低健康平衡值=(100-健康) / 8,最多为 4
var lowBal = Math.min((100-att.Health)/8,4);
//卫生影响指数=(1+0.4*卫生值)
var hiAff = 1+0.4*getData('healthIndex')/100;
//精力低于 25,精力影响指数=(100+精力-25)%。
if(att.Stamina<25){
staAff = 100+att.Stamina-25;
//精力低于 25,额外损失 (25-精力) * 0.2 。
lowBal-=(25-att.Stamina)*0.2;
}else if(att.Stamina>75){
//精力高于 75,精力影响指数=(100+精力-75)%。
staAff = 100+att.Stamina-75;
}
//快乐高于 75,快乐影响指数=(快乐+25)%。
if(att.Happiness>75){
hapAff = att.Happiness+25;
}
//健康低于 75,健康影响指数=(健康+25)%
if(att.Health<75){
heaAff = att.Health+25;
}
//饥饿低于 75,饥饿影响指数= (100-75+饥饿)%。
if(att.Starvation<75){
hgrAff = 100-75+att.Starvation;
//饥饿低于 75,额外损失 (75-饥饿) * 0.15 。
lowBal-=(75-att.Starvation)*0.15;
}
//安逸性格时,安逸影响指数=(100-25*安逸)%。勤奋性格无影响。
var char1 = parseFloat(getData('char1'));
charAff = 100;
if(char1<0){
charAff = 100+25*(char1/100);
}
//节制奢侈
var char4 = parseFloat(getData('char4'));
charAff4 = 100;
if(char4>0){
charAff4 = 100-33*(char4/100);
}else{
charAff4 = 100-40*(char4/100);
}
//健康换日回复=基准值*街区卫生影响指数*性格影响指数
//*快乐影响指数*健康影响指数*精力影响指数*饥饿影响指数
//+低健康平衡值-饥饿额外损失-精力额外损失
//console.log(base,hiAff,charAff,charAff4,hapAff,heaAff,staAff,hgrAff,lowBal);
attAfter.Health=parseFloat(att.Health)+base*hiAff*charAff/100*
hapAff/100*heaAff/100*staAff/100*hgrAff/100*charAff4/100+
lowBal;
//快乐换日回复
staAff = 100;hapAff = 100;heaAff = 100;hgrAff = 100;charAff = 100;
lowBal = 0;hiAff = 0;
//低快乐平衡值=(100-快乐) / 10,最多为 4
lowBal = Math.min((100-att.Happiness)/10,4);
//繁荣影响指数=(1+0.4*繁荣值)
hiAff = 1+0.4*getData('prosperityIndex')/100;
//精力低于 25,精力影响指数=(100+精力-25)%。
if(att.Stamina<25){
staAff = 100+att.Stamina-25;
//精力低于 25,额外损失 (25-精力) * 0.2 。
lowBal-=(25-att.Stamina)*0.2;
}else if(att.Stamina>75){
//精力高于 75,精力影响指数=(100+精力-75)%。
staAff = 100+att.Stamina-75;
}
//健康影响指数=(健康+25)%。
heaAff = att.Health+25;
//饥饿低于 75,饥饿影响指数= (100-75+饥饿)%。
if(att.Starvation<75){
hgrAff = 100-75+att.Starvation;
//饥饿低于 75,额外损失 (75-饥饿) * 0.15 。
lowBal-=(75-att.Starvation)*0.15;
}
//安逸性格时,安逸影响指数=(100+25*安逸)%。勤奋性格无影响。
char1 = parseFloat(getData('char1'));
charAff = 100;
if(char1<0){
charAff = 100-25*(char1/100);
}
//谨慎性格时,谨慎影响指数=(100-25*谨慎)%。急进性格无影响。
var char3 = parseFloat(getData('char3'));
var charAff3 = 100;
if(char3<0){
charAff3 = 100+25*(char3/100);
}
char4 = parseFloat(getData('char4'));
charAff4 = 100;
if(char4>0){
charAff4 = 100+40*(char4/100);
}else{
charAff4 = 100+33*(char4/100);
}
//快乐换日回复=基准值*街区繁荣影响指数*性格影响指数*健康影响指数*精力影响指数*饥饿影响指数+低快乐平衡值
attAfter.Happiness=parseFloat(att.Happiness)+base*hiAff*charAff/100*charAff3/100*charAff4/100*heaAff/100*staAff/100*hgrAff/100+lowBal;
//console.log(base,hiAff,charAff,charAff3,charAff4,heaAff,staAff,hgrAff,lowBal);
//饥饿回复
attAfter.Starvation=Math.max(parseFloat(att.Starvation)*0.9,5);
//最后调整
attAfter.Stamina=Math.min(attAfter.Stamina,attAfter.Health);
for(var x in attAfter){
saveData('d'+x,attAfter[x]);
}
writeETD();
return attAfter;
}
//写入换日后数据
function writeETD(){
var attrs='Stamina,Happiness,Health,Starvation'.split(',');
for(var i=0;i<attrs.length;i++){
var current = attrs[i];
var data = getData('d'+current);
var orgNumHTML = '<span class="Number">'+$('#Status_'+current+' .Number').html()+'</span>';
$('#Status_'+current+' p').html(orgNumHTML + ' / '+parseFloat(data).toFixed(2));
}
}
getChar();
fixStatus();
helloLuoyang();
hideTiles(['AvatarSet','Message','Notifications','Recipes','Collections']);
noRefreshSpeeches();
autoReadMessages();
updateHome();
writeETD();
});
if(unsafeWindow && unsafeWindow.$){
start(unsafeWindow.$);
}else{
start($);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment